.NET

.NET

Reply
Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 1 of 2 (154 Views)
Accepted Solution

Obtain Default Value of an Attribute Definition

154 Views, 1 Replies
03-18-2014 06:04 AM

Hi everyone,

 

This should hopefully be a straightforward  task in AutoCAD .NET, but I'm having trouble figuring it out.

My objective is to look at all attribute definitions within a block definition, and then store the tags and default values into a dictionary.

 

So far I've successfully extracted the tag string, yet I cannot find how to access the default value of the attribute definition.

Here is a snippet of code that builds the dictionary of attributes:

//Iterate through all entities in the block definition.
BlockTableRecord blockDefinition = tr.GetObject(blockTable[blockName], OpenMode.ForRead) as BlockTableRecord; Dictionary<String, String> attributes = new Dictionary<String, String>(); foreach (ObjectId entId in blockDefinition) { Entity entity = tr.GetObject(entId, OpenMode.ForRead) as Entity; if (entity != null) { //If the entity is an attribute definition, append its information to the dictionary above. if (entity is AttributeDefinition) { AttributeDefinition attributeDefinition = entity as AttributeDefinition; attributes.Add(attributeDefinition.Tag, INSERT ATTRIBUTE'S DEFAULT VALUE HERE); } } }

 

Does anyone know how to retreive the attribute definitions default value?

 

 

Thanks much,

Nick

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 2 of 2 (143 Views)

Re: Obtain Default Value of an Attribute Definition

03-18-2014 06:36 AM in reply to: Millerni456

Solved.

 

I was testing on bad data earlier in which attribute tags were the same as their default values.  Because of this, I didn't see that my previously correct code was indeed correct.

 

 

To obtain the default value, retrieve this property:

AttributeDefintion.TextString

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 or visit the Installation and Licensing Forum to get help installing your software.