Add selected "On Screen" entities to selection set

Discussion in 'AutoCAD' started by vindimy, Jun 7, 2007.

  1. vindimy

    vindimy Guest

    Here's how it's done. I'm creating selection set SS001 and adding
    selected objects on screen to it. Anyone any suggestions?

    Dim objSSet As AcadSelectionSet
    Dim intI As Integer
    ReDim ssobjs(0 To ThisDrawing.ActiveSelectionSet.Count - 1) As
    AcadEntity

    Set objSSet = ThisDrawing.SelectionSets.Item("SS001")

    If objSSet Is Nothing Then
    Set objSSet = ThisDrawing.SelectionSets.Add("SS001")
    Else
    objSSet.Clear
    End If

    For intI = 0 To ThisDrawing.ActiveSelectionSet.Count - 1
    Set ssobjs(intI) = ThisDrawing.ActiveSelectionSet.Item(intI)
    Next
    objSSet.AddItems (ssobjs)

    Erase ssobjs


    If you're getting compile error, you might need to add "On Error
    Resume Next" as a first line of code.
     
    vindimy, Jun 7, 2007
    #1
  2. vindimy

    Rodrigues Guest

    here's how i did it:

    Public Sub cmd_select_Click()
    Dim Sset As AcadSelectionSet
    UserForm1.hide
    On Error Resume Next
    Set Sset =
    ThisDrawing.Application.ActiveDocument.SelectionSets.Add("ss1")
    If err.Description = "The named selection set exists" Then
    ThisDrawing.SelectionSets("ss1").Delete
    Set Sset =
    ThisDrawing.Application.ActiveDocument.SelectionSets.Add("ss1")
    End If

    Sset.SelecTonScreen
    Sset.Highlight (True)
    Sset.Clear
    Sset.ErAse
    Sset.Delete

    End Sub

    with this sub, when i click th button the form hides, and the cad
    waits for a selection. when i choose some elements, they are added to
    the selection set named ss1 and highlighted on screen.
    it was very tricky to work with selection sets because even after the
    routine has ended, i cal call the object in this selection set (ss1)
    in other routines to do something with it calling it through:

    Application.ActiveDocument.ActiveSelectionSet

    if it was the last thing you selected you can retrieve it later. on
    the other hand if you don't check if the name exists like it it done
    you'l make it work the first time but you will allways get an
    automation error until you close and open AutoCAD.

    i hope it helps.
     
    Rodrigues, Jun 18, 2007
    #2
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.