Selection set of nested blocks

Discussion in 'AutoCAD' started by Matt W, Nov 2, 2004.

  1. Matt W

    Matt W Guest

    Does anyone have a chunk o' code they'd like to share that will essentially
    create a selection set of blocks nested within an xref??

    Thanks in advance!
     
    Matt W, Nov 2, 2004
    #1
  2. You may have made it past this...but this was given by Acadx.com RIP......
    I modified it a little. It was designed for Excel VBA. It's a little
    buggy, as I never found a way to clear the selection set that was created.
    But it may can be applied to your goal. Good luck

    The reset was to check if creating the SS would fail. If fail, then I would
    tell the user to restart both Excel and Autocad.
    Basically you have to build an array for the filter.

    Ricky M. Medley
    Houston

    Public Function CreateSelectionSet(Reset As Boolean, Optional ssName As
    String = "ss") As AcadSelectionSet
    'Code by AcadX
    Dim ss As AcadSelectionSet

    On Error Resume Next
    Set ss = AcadApplication.ActiveDocument.SelectionSets(ssName)
    If Err Then
    Err.Clear
    Set ss = AcadApplication.ActiveDocument.SelectionSets.Add(ssName)
    End If
    ss.Clear
    If Err Then Reset = True
    Set CreateSelectionSet = ss
    End Function


    '....continued from calling code

    'Now walk through CAD file and for each block in new selectionset...find
    appropriate line item in Excel.
    MaxRow = objSheetPull.UsedRange.Rows.Count
    Set ss = CreateSelectionSet(Reset, "ssBlocks") 'AcadX function
    If Reset = True Then GoTo RESET_EXCEL:
    fType(0) = 0: fType(1) = 2
    fData(0) = "INSERT": fData(1) = "BOM Block"
    ss.Select acSelectionSetAll, , , fType, fData
     
    Ricky M. Medley, Nov 3, 2004
    #2
  3. Matt W

    Jeff Mishler Guest

    Not a selection set, but an array of all block inserts in an Xref.

    Function GetNestedBlocks(oXref As AcadExternalReference) As Variant
    Dim oEnt As AcadEntity
    Dim vVal() As Variant
    Dim I As Long

    ReDim vVal(0 To ThisDrawing.blocks.Item(oXref.Name).Count)
    For Each oEnt In ThisDrawing.blocks.Item(oXref.Name)
    If TypeOf oEnt Is AcadBlockReference Then
    Set vVal(I) = oEnt
    I = I + 1
    End If
    Next
    ReDim Preserve vVal(0 To I - 1)
    GetNestedBlocks = vVal

    End Function
     
    Jeff Mishler, Nov 3, 2004
    #3
  4. Matt W

    Matt W Guest

    Thanks for the feedback guys.
    Shortly after I sent this post, there was a "slight" change in plans.

    What I ended up doing was searching each xref for a particular block name
    and some attribute info, then pushing that info to a Scripting Dictionary.

    From there, I'm using the dictionary entries for a report that I'm
    generating in Excel as well as a table in AutoCAD.

    Thanks again!
     
    Matt W, Nov 3, 2004
    #4
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.