Block Attribute Problem

Block Attribute Problem

Anonymous
Not applicable
463 Views
2 Replies
Message 1 of 3

Block Attribute Problem

Anonymous
Not applicable
I have a small sub that inserts an exesting block. The inserted block has a single attribute, but the AttributeCollection is always empty. If I explode the inserted block, the attribute appears, but I cant get a reference to it in code.
0 Likes
464 Views
2 Replies
Replies (2)
Message 2 of 3

chiefbraincloud
Collaborator
Collaborator
you need to add the attribute references to the block reference 'manually' when the block is inserted. If you have done other forms of autocad programming (COM, VBA, LSP) this is counterintuitive because you never had to do it before. This snip should go into your code immediately after you add the BlockReference to the Transaction.


If btr.HasAttributeDefinitions Then



Dim AtDef As AttributeDefinition, AttRef As AttributeReference



For Each SubEntId As ObjectId In btr



If SubEntId.ObjectClass.Name = "AcDbAttributeDefinition" Then



AtDef = TM.GetObject(SubEntId, OpenMode.ForRead, False, True)



AttRef = New AttributeReference



AttRef.SetAttributeFromBlock(AtDef, br.BlockTransform)



br.AttributeCollection.AppendAttribute(AttRef)



T.AddNewlyCreatedDBObject(AttRef, True)



AtDef.Dispose()



AttRef.Dispose()



End If



Next



End If

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks for the help. I am updating some of my code to get away from using the COM.
0 Likes