Posts: 13
Registered: ‎06-01-2010
Message 1 of 4 (455 Views)
Accepted Solution

Issue with Block Attributes.

455 Views, 3 Replies
07-19-2010 06:05 AM

I have some code which is inserting a block with attributes and setting the TextString property as the block is inserted. (This works appart from this issue)

Dim attColl As AttributeCollection = newBlockReference.AttributeCollection

Dim entID As ObjectId

Dim ent As Entity


For Each entID In newBlockDef

ent = entID.GetObject(OpenMode.ForRead)

If TypeOf ent Is AttributeDefinition Then

Dim attDef As AttributeDefinition = CType(ent, AttributeDefinition)

Dim attRef As New AttributeReference

attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform)


attRef.TextString = "SOMETHING"

currentTransaction.AddNewlyCreatedDBObject(attRef, True)

End If



When the block is inserted and the attributes are set using this code, double clicking on the block in the drawing and examining the attributes in the "Enhanced Attribute Editor" the prompt values for the attributes are all mixed up.


The block definition has multiple attributes with prompt text entered against them in the block definition.


Tag: DEVICE, PROMPT:"Enter Device Reference", VALUE:"AMMETER"

Tag: PART#, PROMPT: "Enter Actual Part #", VALUE:"E242-75A"


After the insert using the above code the Prompt might appear like this:

Tag: DEVICE, PROMPT:"Default Mounting Location", VALUE:"AMMETER"

Tag: PART#, PROMPT: "Enter Device Reference", VALUE:"E242-75A"


It appears as though the prompt text is being set as the prompt text from the previous attribute whenever it is empty.


FYI if the block is inserted manually using the AutoCAD insert command the attribute definitions are correct so i have to assume im doing something wrong here.


Any help would be appreciated.


Posts: 13
Registered: ‎06-01-2010
Message 2 of 4 (436 Views)

Re: Issue with Block Attributes.

07-20-2010 05:02 AM in reply to: PSharpe

A little more information this appears to be tied in with constant attributes as this code appears to be making constant attributes editable so im definatley doing somehting wrong here

Valued Mentor
Posts: 305
Registered: ‎01-26-2005
Message 3 of 4 (434 Views)

Re: Issue with Block Attributes.

07-20-2010 05:32 AM in reply to: PSharpe

Don't create an AttributeReference for constant attribute definitions.

AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011

Posts: 13
Registered: ‎06-01-2010
Message 4 of 4 (431 Views)

Re: Issue with Block Attributes.

07-20-2010 05:35 AM in reply to: caddzone

I just figured that out and have resolved this issue. The problem i had was that i was checking the IsConstant attribute of the AttributeReference (as you say) rather than the Constant attribute of the AttributeDefinition before deciding how to process it.


Spent hours going round with this one for it to be so simple!!


Problem solved.


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.