It became an interesting topic now.
You code looks OK to me. I have similar code (testing if an application name
is registered first, if not add one; then attach XData with taht application
name to an Entity.), it just work well with both Acad2006 and 2007 on
different computers.
So, you need to identify which line of the code is the reason. For example:
1. try use smaller ResultBuffer, say, only attach 1 piece data, rather than
5; or
2. try set the XData with different type, say, interger, instead of string;
or
3. try different BlockReference, or even different type of Entity; or
4. Not passing COM AcadBlockRefernece to the method, passing in an valid
DBObject's ObjectId directly instead; or...
These different test may or may not reveal the cause of slowness, but you
have to try. I believe you are not the first one who use .NET API to set
XData, I did not heard such a slowness until now. YOu may even try to run
the same code on other computer to eliminate possible hardware issue, or
write equivalent VBA code to set the same XData to the same BlockReference,
to see what happens.
Sorry for not being more help, but I'd like to hear the result of whatever
you tried.
wrote in message news:5747834@discussion.autodesk.com...
Well, I changed the code to use .NET API and the same problem occurs. This
is my code:
static public void XDataCreateBlock2
(Autodesk.AutoCAD.Interop.Common.AcadBlockReference acadBlock)
{
Database acadDB;
TransactionManager acadTManager;
RegAppTable regAppTable;
acadDB = Application.DocumentManager.MdiActiveDocument.Database;
acadTManager = acadDB.TransactionManager;
using(Transaction trans = acadTManager.StartTransaction())
{
regAppTable = (RegAppTable)trans.GetObject(acadDB.RegAppTableId,
OpenMode.ForWrite);
if (regAppTable.Has("myAppName") == false)
{
RegAppTableRecord xdRec;
xdRec = new RegAppTableRecord();
xdRec.Name = "myAppName";
regAppTable.Add(xdRec); acadTManager.AddNewlyCreatedDBObject(xdRec, true);
}
trans.Commit();
}
try
{
using(Transaction trans = acadTManager.StartTransaction())
{
Entity entity;
ObjectId objID;
ResultBuffer resultBuffer;
objID = new ObjectId();
objID.OldId = acadBloco.ObjectID;
entity = (Entity)trans.GetObject(objID, OpenMode.ForWrite, false, true);
resultBuffer = new ResultBuffer();
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataRegAppName), "myAppName"));
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataAsciiString),
"adsfasdfasdf"));
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataAsciiString),
"asdfasdfasdf"));
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataAsciiString),
"adfasdfasdf"));
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataAsciiString),
"asfasdfasdfasdf"));
resultBuffer.Add(new
TypedValue(Convert.ToInt16(DxfCode.ExtendedDataAsciiString),
"asasdfasdfasdfasdf"));
entity.XData = resultBuffer;
trans.Commit();
}
}
catch(Exception exp)
{
}
The last call to "trans.Commit();" takes 2 minutes and 50 seconds to
complete.