Issue with Block Attributes.

Issue with Block Attributes.

Anonymous
Not applicable
1,326 Views
3 Replies
Message 1 of 4

Issue with Block Attributes.

Anonymous
Not applicable

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)

attColl.AppendAttribute(attRef)

attRef.TextString = "SOMETHING"

currentTransaction.AddNewlyCreatedDBObject(attRef, True)

End If

Next

 

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.

e.g.

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.

 

0 Likes
Accepted solutions (1)
1,327 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

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

0 Likes
Message 3 of 4

Anonymous
Not applicable
Accepted solution

Don't create an AttributeReference for constant attribute definitions.

0 Likes
Message 4 of 4

Anonymous
Not applicable

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.

 

0 Likes