PDA

View Full Version : Count BlockReference entities



axa2001ro
2004-06-11, 12:52 PM
Hello!

Is there an easy way ( other than the example bellow ) to count the block reference entities from ModelSPace.


Dim iCount As Integer
Dim objEntity as AcadEntity

For each objEntity in ThisDrawing.ModelSpace
If typeof (objEntity) is AcadBlockReference then
iCount=iCount+1
End if
next objEntity

Thank you!

Bobby C. Jones
2004-06-14, 08:28 PM
I don't know of an easier way as far as coding goes. There are other ways, such as a filtered selection set. Does the code you show not do something that you want it to do?

jwanstaett
2004-06-16, 01:11 PM
Yes the BLOCK_RECORD Entity type has a list of all block inserted in the drawing
the BLOCk_RECORD is the object set my ThisDrawing.Blocks.Item("xx")
but VBA dose not let you get to the List of blocks

But you can use VisualLisp to get the list from the BLOCK_RECORD
I Attach a VBA program that show how to do it

The programm use two Class Modules
1. expBlock use to Get a Collection that has all the BlockReference for the block in it

2. TalkToVlisp this Class let expBlock Class use VisualLisp to get the data form the
BLOCK_RECORD


The code use is for Autocad 2002 The TalkToVlisp CLass
will need Vl.Application.1 change in this line to work with 2004
Set myvl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")

----if you know what to change plase post it, I would like to know too------


If Autcad did not change the Format of the BLOCK_RECORD in 20004
The expBlock program should work in 2004

UseForm1 in the Attched program show how to use the Class

the expBlock Class also will gave you a Collection of Attribues in the block
or get a Collection of the AttributeReference of any BlockReference in the block Collection

The Collection of Attribues and AttributeReference are key on the UCase(TagString)
so unlike the GetAttributes() function of the BlockReference object you can get the
Attribues or AttributeReference by UCase(TagString)



note:
you must have Loaded Visual LISP extensions to AutoLISP for TalkToVlisp to work

(vl-load-com)

This function loads the extended AutoLISP functions provided with Visual LISP. The Visual LISP extensions implement ActiveX and AutoCAD reactor support through AutoLISP, and also provide ActiveX utility and data conversion functions, dictionary handling functions, and curve measurement functions.

If the extensions are already loaded, vl-load-com does nothing.

04/22/06 just test in ADT 2007 work ok if you change VL.Application.1 to VL.Application.16

marin_andrei
2004-06-21, 11:40 AM
I dont know any other way to acces the BlockRefs in a drawing. You can try with EntityName:
For each objEntity in ThisDrawing.ModelSpace
If objEntity.EntityName = "AcDbBlockReference" then
iCount=iCount+1
End if
next objEntity

jwanstaett
2006-04-21, 01:54 PM
tested attachment in autocad 2007 work ok see above post