.NET

Reply
*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 =
dbCurrent.TransactionManager;


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);

}

}

tr.Commit();

} // end of using

}


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


"Zhongwei Xia" schrieb im Newsbeitrag
news:4969745@discussion.autodesk.com...
I just tried it. I works great.
I appreciate your helps very much.
Zhongwei


"Tony Tanzillo" wrote in message
news:4969620@discussion.autodesk.com...
>> 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?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4969406@discussion.autodesk.com...
Thank you for your email.
Distinguished Contributor
RolandF
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

Announcements
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