Block collection using ObjectDBX

Discussion in 'AutoCAD' started by Matt W, Feb 24, 2004.

  1. Matt W

    Matt W Guest

    How can I get the names of the blocks in a drawing (or drawings) using ObjectDBX??
    I've tried this snippet of code, but it doesn't seem to work...
    Anyone have any ideas??

    ' = = = SNIP = = = '

    Public dbxDoc As AxDbDocument

    ' = = = SNIP = = = '

    Dim objEnt As AcadBlockReference

    Set dbxDoc = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument.16")

    For Each objEnt In dbxDoc.Blocks
    If TypeOf objEnt Is AcadBlockReference Then
    Debug.Print objEnt.Name ' Nothing happens here even though there are over 100 blocks in the drawing
    End If
    Next objEnt

    ' = = = SNIP = = = '

    The rest of the code is as follows...
    1) Determine the names of drawings within a given directory
    2) Open each drawing using ObjectDBX
    3) Try (and I stress the word TRY since I haven't been able to get this to work) to get a listing of the blocks in each drawing
    4) Process the block information
     
    Matt W, Feb 24, 2004
    #1
  2. DBX works just like AutoCAD - there are no BlockReferences in the Blocks
    table! Blocks are descriptions and BlockReferences are the pointers to the
    descriptions. If you want to search the drawing for 'used' blocks, you need
    to search thru model space and all the layouts for BlockReferences.
     
    Mike Tuersley, Feb 24, 2004
    #2
  3. Matt W

    Jeff Mishler Guest

    Matt,
    Your Set dbxDoc = ...... only creates a document. You must use the open
    method to get an actual drawing.

    So your code should look like this:

    Set dbxDoc = blah
    dbxDoc.Open (dwg_to_open_for_reading)

    Next, I don't think you want the *Model & *Paper space blocks, so I'd
    iterate through only the Modelspace collection, rather than the block
    collection:

    Dim objEnt as AcadEntity
    Dim objBlock as AcadBlockReference

    For Each objEnt in dbxDoc.Modelspace
    if typeof objEnt is AcadBlockReference then
    Set objBlock = objEnt
    Debug.Print objBlock.Name
    Next

    HTH,
    Jeff

    How can I get the names of the blocks in a drawing (or drawings) using
    ObjectDBX??
    I've tried this snippet of code, but it doesn't seem to work...
    Anyone have any ideas??

    ' = = = SNIP = = = '

    Public dbxDoc As AxDbDocument

    ' = = = SNIP = = = '

    Dim objEnt As AcadBlockReference

    Set dbxDoc =
    ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument.16")

    For Each objEnt In dbxDoc.Blocks
    If TypeOf objEnt Is AcadBlockReference Then
    Debug.Print objEnt.Name ' Nothing happens here even though there
    are over 100 blocks in the drawing
    End If
    Next objEnt

    ' = = = SNIP = = = '

    The rest of the code is as follows...
    1) Determine the names of drawings within a given directory
    2) Open each drawing using ObjectDBX
    3) Try (and I stress the word TRY since I haven't been able to get this to
    work) to get a listing of the blocks in each drawing
    4) Process the block information
     
    Jeff Mishler, Feb 24, 2004
    #3
  4. Matt W

    Matt W Guest

    Ahhh.....
    That did it!

    Thanks, Jeff!
     
    Matt W, Feb 24, 2004
    #4
  5. Matt W

    Jeff Mishler Guest

    Jeff Mishler, Nov 30, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.