*Zhongwei Xia
Post 11 of 12

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
172 Posts
1 Kudo
Registered: ‎11-19-2003
Post 12 of 12

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!