*Zhongwei Xia
Message 11 of 12 (212 Views)

Re: How to insert block with attributes into a drawing using .NET

09-30-2005 08:18 AM in reply to: *Zhongwei Xia
Following is the code to insert AttributeReference.

public static void InsertBlockAttibuteRef(ObjectId blockDefID,
BlockReference blkRef,

string strAttributeText, Point3d ptInsert)


Database dbCurrent = HostApplicationServices.WorkingDatabase;

Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =

using (Transaction tr = tm.StartTransaction())


DBObject objBlkRef = tr.GetObject(blkRef.ObjectId, OpenMode.ForWrite);

BlockTableRecord btAttRec;

btAttRec = (BlockTableRecord)tr.GetObject(blockDefID, OpenMode.ForRead);

foreach (ObjectId idAtt in btAttRec)


Entity ent = (Entity)tr.GetObject(idAtt, OpenMode.ForRead);

if (ent is AttributeDefinition)


AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform);

attRef.TextString = strAttributeText;

ObjectId idTemp = blkRef.AttributeCollection.AppendAttribute(attRef);

tr.AddNewlyCreatedDBObject(attRef, true);




} // end of using


wrote in message news:4971700@discussion.autodesk.com...
Is it possible for you to post the final code?

"Zhongwei Xia" schrieb im Newsbeitrag
I just tried it. I works great.
I appreciate your helps very much.

"Tony Tanzillo" wrote in message
>> SetAttributeFromBlock() can't be called.
>> If I call this function, attributes will go to (0,0,0) position.

Did you pass the value of the BlockTransform property of
the BlockReference object to the second argument to
SetAttributesFromBlock, as I had mentioned earlier?


AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006

"Zhongwei Xia" wrote in message
Thank you for your email.
Distinguished Contributor
Posts: 172
Registered: ‎11-19-2003
Message 12 of 12 (212 Views)

Re: How to insert block with attributes into a drawing using .NET

10-03-2005 02:38 AM in reply to: *Zhongwei Xia
Thank you!

Roland Feletic
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!