.NET

Reply
Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 1 of 7 (2,059 Views)

Add Attributes to Block References

2059 Views, 6 Replies
02-09-2012 11:46 AM

Hey Everyone,

 

I think what i'm trying to do is pretty simple. I've already had some help designing code whereas I was able to take the attributes from block references in independent .dwg files and and bring them across to a new drawing via import. At this point, there are a few attributes that I would like to be able to add to each block reference once it's created. I've designed a GUI where users can input data, and this input (string data) I'd like to add to the block reference as a tag and a corresponding value.

 

The basics I understand are to create an attribute reference object. Set the properties/parameters for this object (tag and value (originally as a string) and them append the attribute to the block reference. What i don't know how to do is to actually create the new tags and values in the code so that they can later be appended. I'm in C# and so far i've got this:

 

foreach (ObjectId id in blockBtr)
{
if (id.ObjectClass == RXClass.GetClass(typeof(AttributeDefinition)))
{
AttributeDefinition attdef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
AttributeReference attref = new AttributeReference();
attref.SetAttributeFromBlock(attdef, bref.BlockTransform);

 

// here is where I would like to specify my new tags and values


bref.AttributeCollection.AppendAttribute(attref);
tr.AddNewlyCreatedDBObject(attref, true);



}

}

 

pCenter