See the top rated post in this thread. Click here

Results 1 to 5 of 5

Thread: Count BlockReference entities

  1. #1
    Member
    Join Date
    2002-09
    Posts
    10
    Login to Give a bone
    0

    Default Count BlockReference entities

    Hello!

    Is there an easy way ( other than the example bellow ) to count the block reference entities from ModelSPace.
    Code:
              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!

  2. #2
    Active Member Bobby C. Jones's Avatar
    Join Date
    2001-08
    Location
    Texas
    Posts
    62
    Login to Give a bone
    1

    Default Re: Count BlockReference entities

    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?

  3. #3
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Count BlockReference entities

    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
    Attached Files Attached Files
    Last edited by jwanstaett; 2006-04-21 at 01:38 PM. Reason: up date for 2007

  4. #4
    Member
    Join Date
    2004-05
    Posts
    3
    Login to Give a bone
    0

    Default Re: Count BlockReference entities

    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

  5. #5
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Count BlockReference entities

    tested attachment in autocad 2007 work ok see above post
    Last edited by jwanstaett; 2006-04-21 at 02:09 PM.

Similar Threads

  1. How i can sweep an BlockReference and find entities without explode
    By MarceloRocha777 in forum VBA/COM Interop
    Replies: 0
    Last Post: 2013-06-05, 02:55 PM
  2. DynamicBlock a look inside a BlockReference
    By Marcio Cartacho in forum Dot Net API
    Replies: 1
    Last Post: 2011-07-20, 09:40 PM
  3. How to Delete Multiple Instances of a BlockReference?
    By brad.moon126662 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2007-10-02, 02:36 PM
  4. Replies: 1
    Last Post: 2006-04-23, 06:16 PM
  5. Replies: 0
    Last Post: 2005-07-08, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •