listbox of blocks in drawing

Discussion in 'AutoCAD' started by John Coon, Jul 24, 2004.

  1. John Coon

    John Coon Guest

    Hi Group,

    What the heck am I doing wrong. I am trying to populate a ListBox1 or
    MessageBox with the block names existing in my drawing.
    This only reports one block. I checked the blockSS and I have the correct
    total for blocks in the drawing and if I step through the blocknames appear
    with the count but they are not added to the BlockList. ? additionally what
    will happen if I have more than one block with the same name. ? will it
    report each instance or just the blockname for the group.

    Ultimately I want to select blockname in listbox and have it open another
    drawing and insert pathed details drawing for the block in the my design
    drawing.

    Thanks for all your help. Have a great day.

    Private Sub CommandButton1_Click()
    Dim fType(0) As Integer, fData(0)
    Dim objBlock As AcadBlockReference
    Dim BlockSS As AcadSelectionSet
    Dim BlockList As String
    On Error Resume Next
    Dim i As Integer
    Set BlockSS = ThisDrawing.SelectionSets("BlockSS")
    If Err Then Set BlockSS = ThisDrawing.SelectionSets.Add("BlockSS")
    BlockSS.Clear
    fType(0) = 0: fData(0) = "INSERT"
    BlockSS.Select acSelectionSetAll, , , fType, fData

    For Each objBlock In BlockSS
    For i = 0 To objBlock.Count - 1
    Next i

    BlockList = objBlock.Name

    Next objBlock
    'UserForm1.ListBox1.Clear
    'UserForm1.ListBox1.AddItem (BlockList)

    MsgBox BlockList

    End Sub
     
    John Coon, Jul 24, 2004
    #1
  2. John Coon

    Mark Propst Guest

    does this work?

    Private Sub CommandButton1_Click()
    Dim fType(0) As Integer, fData(0)
    Dim objBlock As AcadBlockReference
    Dim BlockSS As AcadSelectionSet
    Dim BlockList As String
    '----------added
    Dim sBlkName as String
    '----------moved
    UserForm1.ListBox1.Clear
    On Error Resume Next
    Dim i As Integer
    Set BlockSS = ThisDrawing.SelectionSets("BlockSS")
    If Err Then Set BlockSS = ThisDrawing.SelectionSets.Add("BlockSS")
    BlockSS.Clear
    fType(0) = 0: fData(0) = "INSERT"
    BlockSS.Select acSelectionSetAll, , , fType, fData

    For Each objBlock In BlockSS
    '----------added
    sBlkName = objBlock.Name
    '----------modified
    BlockList = Blocklist & sBlkName & vbcrlf
    '----------moved/modified
    UserForm1.ListBox1.AddItem (sBlkName)
    Next objBlock
    '----------depending on length of string, this could be a problem
    '----------but ok while debugging
    MsgBox BlockList

    End Sub
    hope that helps
    Mark
     
    Mark Propst, Jul 24, 2004
    #2
  3. John Coon

    John Coon Guest

    Mark,

    Thanks that did it Mark. BlockList & sBlkName was the key. adding the next
    sBlkName to the BlockList where I was just getting the next block name and
    not adding it to the list. you guys are great.

    If I could ask another question. How do I handle blocks with the same name.
    What type of filter will capture the block group name. How can I get the
    listBox to display just one display of block "A" when I have 10 block "A" in
    my drawing. Would it be something like look at the pervious name and if it
    is already included in the list then nil or will that place a empty record
    space in the blocklist.

    As always thank you for your help. Have a great day.
    John Coon
     
    John Coon, Jul 25, 2004
    #3
  4. John Coon

    Mark Propst Guest

    here's one option of handling that...

    Private Sub CommandButton1_Click()
    Dim fType() As Integer, fData() As Variant
    Dim objBlock As AcadBlockReference
    Dim BlockSS As AcadSelectionSet
    Dim BlockSS2 As AcadSelectionSet
    Dim BlockList As String
    Dim sReport As String

    Dim sBlkName As String
    Me.ListBox1.Clear
    On Error Resume Next
    Dim i As Integer
    Set BlockSS = ThisDrawing.SelectionSets("BlockSS")
    If Err Then Set BlockSS = ThisDrawing.SelectionSets.Add("BlockSS")
    BlockSS.Clear
    ReDim fType(0)
    ReDim fData(0)

    fType(0) = 0: fData(0) = "INSERT"
    BlockSS.Select acSelectionSetAll, , , fType, fData

    Set BlockSS2 = ThisDrawing.SelectionSets("BlockSS2")
    If Err Then Set BlockSS2 = ThisDrawing.SelectionSets.Add("BlockSS2")
    BlockSS2.Clear

    ReDim fType(1) As Integer, fData(1) As Variant
    For Each objBlock In BlockSS
    '----------added
    sBlkName = objBlock.Name
    'if insert is not already on list
    If Not InStr(1, BlockList, sBlkName, vbTextCompare) > 0 Then
    'get sel set of that insert
    BlockSS2.Clear
    fType(0) = 0: fData(0) = "INSERT": fType(1) = 2: fData(1) = sBlkName

    BlockSS2.Select acSelectionSetAll, , , fType, fData

    'report name and count
    sReport = sBlkName & " (" & CStr(BlockSS2.Count) & ")"
    BlockList = BlockList & sReport & vbCrLf


    Me.ListBox1.AddItem (sReport)
    End If

    Next objBlock

    MsgBox BlockList

    End Sub

    hope that gives you a starting point to work from
    :)
    Mark
     
    Mark Propst, Jul 25, 2004
    #4
  5. John Coon

    John Coon Guest

    Mark,

    Thank you so much, I'll run your code and see if I can use it as a starting
    point for what I'm trying to accomplish.

    John Coon
     
    John Coon, Jul 25, 2004
    #5
  6. seems to be a popular request ;-)

    Here's what I ended up doing:

    For Each AcadBlock In AcadDoc.Blocks
    BlockName = AcadBlock.Name
    If Not BlockName Like "[*]*" Then frmMain.lstCurrentBlocks.AddItem
    AcadBlock.Name
    Next AcadBlock


    Thank you to those who made it simple for me... :-D


    cyber
     
    cyberstrategist, Jul 26, 2004
    #6
  7. If you are going to set a variable for the block name, you might as well use
    it. ;^)

    BlockName = AcadBlock.Name
    If Not BlockName Like "[*]*" Then frmMain.lstCurrentBlocks.AddItem BlockName


    --
    R. Robert Bell


    seems to be a popular request ;-)

    Here's what I ended up doing:

    For Each AcadBlock In AcadDoc.Blocks
    BlockName = AcadBlock.Name
    If Not BlockName Like "[*]*" Then frmMain.lstCurrentBlocks.AddItem
    AcadBlock.Name
    Next AcadBlock


    Thank you to those who made it simple for me... :-D


    cyber
     
    R. Robert Bell, Jul 26, 2004
    #7
  8. Especially since I didn't in that code originally... <grr>
     
    R. Robert Bell, Jul 26, 2004
    #8
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.