.NET

.NET

Reply
*Zhongwei Xia
Message 11 of 12 (227 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 (227 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
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.