*Zhongwei Xia
Message 11 of 12 (185 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 (185 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community