PDA

View Full Version : VBA - Attributes using old tag when exploded



EGoldberg
1st Jun 2010, 03:24 pm
I am trying to finish up my program in VBA and I have one final problem.

When I update a block's attribute tag (not text) because we have two attributes with the same tag name and they need to be redefined, I can update it but as soon as it is exploded it goes back to the old name.

That is, I've updated the tag successfully, I can see that I have in properties and the Enhanced Attribute Editor, but when I use -battman, it still says the old tag and when I use explode, it goes from my new tag name to the old. Is there anyway to sync this up in VBA?

The code for editing my tag is as follows


attList = blk.GetAttributes
attList(3).TagString = "ASB2"
attList(3).Update

What am I missing? I'm not much of an AutoCAD user so I'm not sure. Thanks for your help in advance.

Lee Mac
1st Jun 2010, 03:29 pm
When exploding / syncing, the block definition as found in the block table will be used I believe.

EGoldberg
1st Jun 2010, 05:04 pm
Is there any way to access the block table in VBA? If you do not know about VBA what about LISP? Is there a particular definition that is accessed to alter the data via a programming language?

Lee Mac
1st Jun 2010, 05:08 pm
Yes, just use the item method on the blocks collection and then you can iterate through the objects that make up the block. :)

Lee Mac
1st Jun 2010, 05:09 pm
in LISP it would be:



(vlax-for SubObj (vla-item
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
"BlockName"
)
...

)

EGoldberg
1st Jun 2010, 05:41 pm
Lee, thank you so much. I was able to translate the LISP heirarchy to VBA and figure it out. For those who might run into the same problem, to step through the blocks rather than their references, see the following code.


For Each ent In ThisDrawing.Blocks
If TypeOf ent Is AcadBlock Then
...
end if
next

Lee Mac
1st Jun 2010, 05:50 pm
Glad I could help :)