Is there a way in vba to test a block to see if its anonymous? Or, is the only way in LISP and test the value of group code 70?
Thx,
Kevin.
|
Is there a way in vba to test a block to see if its anonymous? Or, is the only way in LISP and test the value of group code 70?
Thx,
Kevin.
I'm pretty sure that an anonymous block's name will always begin with "*U"
Something like this?Originally Posted by KevinBarnett
Code:Sub temp() Dim obj As AcadEntity For Each obj In ThisDrawing.ModelSpace If obj.ObjectName = "AcDbBlockReference" Then tmp = obj.EffectiveName If InStr(1, tmp, "*U", vbTextCompare) Then Debug.Print tmp End If End If Next obj End Sub
R.K. McSwain | CAD Panacea |
Here we go again, hidden treasures in the object model. It's such a pity this property is in the BlockReference object and not the Block object. Out of curiosity, have you looked at VB.Net yet or are you still coding in VBA?
Originally Posted by KevinBarnett
VBA.
The reason you have to test "EffectiveName" is that Dynamic block insertions become "anonymous" as soon as they are modified.
R.K. McSwain | CAD Panacea |
While it's true that the EffectiveName is a property of the BlockRef, you can still check if a BlockDef is anonymous by checking it's Name property. So I'm not sure what you mean by "Here we go again".Originally Posted by KevinBarnett
Jeff
Technically true, but as mentioned, the Name property of a dynamic block changes as soon as it is modified using one of it's dynamic properties.Originally Posted by miff
At that point, if you only check the Name property for "*U", you could be looking at an anonymous block or a modified dynamic block.
The EffectiveName property will reflect "*U" only for true anonymous blocks.
R.K. McSwain | CAD Panacea |
OK, let's back up a bit. Kevin asked about checking if a Block is anonymous, and since he mentioned the lisp method of checking the Group 70 code which is a part of the Block Definition and not the insert, it made sense to answer that. And since the Block object does NOT have an EffectiveName property I felt obliged to mention that the Name property of a Block, not BlockReference, can be used to determine anonymity.
Jeff
Jeff,
The Name property is dangerous. All because a block is named "*U" it is not necessarily an anonymous block. I was unlucky enough to encounter drawing data made my a non Autodesk CAD system. Somehow they managed to use *'s in the block names an thats where my troubles began. I wrote code to remove the invalid characters, making the block names AutoCAD compliant - (yes I did AUDIT the drawing, the result was awful!). Thats why I need to test for anonymous. It would have been great if VBA in Acad included IsAnonymous, like IsLayout. But it does not. I solved it by a little LISP, testing the value of group code 70. Still, it was great to find that additional info - EffectiveName, will come in useful.
Thanks guys.