cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pick command and select sets with loops.

Pick command and select sets with loops.

I ran into an issue today and I have duplicated the issue in both 2021 and 2025. It seems as though if you are using the pick command from the command manager and try to use it in a looping situation to add a pick to a Select Set the pick reset the Select set until the end of the pick. From what I can tell it should iterate through the loop adding the entities to the Select Set and highlighting the appropriate entities. But it doesn't do that until the Pick command is escaped out of or ended. 

 

Here is the code that I used I have tried a Do loop, While loop and a goto command, and all have the same outcome. 

 

 

Community thread talking about this issue. 

 

https://forums.autodesk.com/t5/inventor-programming-ilogic/select-sets-do-loops-and-winforms/m-p/129...

8 Comments
YuhanZhang
Autodesk

@Tiffany_Hayden_ 

 

Can you explain your purpose when use the Pick command?

 

Thanks,

Rocky

Tiffany_Hayden_
Collaborator

@YuhanZhang  When I use the pick command, most of the time I'm adding an object to a collection or I'm adding to a select set. But because the pick command wipes the select set on each pick call it makes it not possible. I would like that not to happen or at least have an option not to wipe the select set in the call. 

 

The purpose of using the pick and adding to the select set is to show the user what they have selected. The work around for this is to loop through each object and collect them into a object collection. Create a highlight set and change the color of each object for instance sketchline to the highlight set color. After the loop has finished change the color back to the default color and add the instance to a select set so the user can cancel the selection anytime they wish. Highlight set doesn't work like a select set does. 

YuhanZhang
Autodesk

Hi @Tiffany_Hayden_ 

The CommandManager.Pick method is provided to do a single selection for users to get an object to process. If you want to do more complex selection operation I suggest to use the SelectEvents which provides more functions than Pick. The SelectEvents usually is used when customer starts a custom command and require to select multiple objects as input for later processing.  Can you check if the SelectEvents can satisfy your requirement there?

 

You can find documentation for SelectEvents as below:

Inventor 2025 Help | SelectEvents Object | Autodesk

 

Thanks,

Rocky

 

 

 

Tiffany_Hayden_
Collaborator

@YuhanZhang Select events can be difficult if you are dealing with an interactive form. That is why I love the pick command is because it continues to be available through any other interactions. I wonder if it would be possible to create another functionality in the API called MultiPick. Is would allow you to continue the pick command and also keep the select set as you go. It could return back a object collection. I've used the pick command for many years now and have used it more frequently to collect objects chosen by the user. 

 

I know the SelectEvents can be daunting to some beginners this might be  a good middle ground if it's possible.

 

Thanks! 

 

YuhanZhang
Autodesk

Hi @Tiffany_Hayden_ 

The CommandManager.Pick command is similar to the selection in a command(like in a feature creation dialog you can select some geometries),  when the command is terminated(cancelled or applied), the selection status will be cleared. 

If you want to mimic the multiple selection using the Pick command, you can check if below logic(VBA code) is working for you:

 

Sub Example()
        Dim selectedSketchLine As SketchLine
        Dim activeHighlightSet As HighlightSet
        Set activeHighlightSet = ThisApplication.ActiveDocument.CreateHighlightSet()
        Dim sketchObjectCollection As ObjectCollection
        Set sketchObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
          
        Do
           Set selectedSketchLine = Nothing
           Set selectedSketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Select the Sketchline or hit ESCAPE...")

            If Not (selectedSketchLine Is Nothing) Then
               Call sketchObjectCollection.Add(selectedSketchLine)
               Call activeHighlightSet.AddItem(selectedSketchLine)
                
            End If
        Loop Until selectedSketchLine Is Nothing
                
        ' process the selected entities
        ' ...
        Call MsgBox("Process selected " & sketchObjectCollection.Count & " entities...")
        ' after processing, clear the highlight set
        activeHighlightSet.Clear
        activeHighlightSet.Delete
End Sub

 

Thanks,

Rocky

Tiffany_Hayden_
Collaborator

@YuhanZhang Yes that is exactly what I did. Using the highlight set. But I had to change the color of the object in my case sketchline because the highlight set clears as well weirdly in some situations. So I just changed the color of the sketchline to the highlight set color and then after the pick command ends by hitting escape I return it back to the default color. It did seem to be a work around. I was just asking for a more streamlined solution that wasn't depending on the highlight set or select set because they are both volatile.  The forum post in my original posting has all that I tried. You can see what my final solution was. Hope that is helpful. 

YuhanZhang
Autodesk

@Tiffany_Hayden_ 

 

Below is a VBA code sample to make use of SelectEvents to do multiple selection, it does not use HighlightSet, you can make use of it in your code to replace the CommandManager.Pick function.

 

Module code:

Public Sub TestSelection()
    ' Create a new clsSelect object.
    Dim oSelect As New clsSelect
    Call oSelect.Pick(kSketchCurveLinearFilter)
End Sub

Class Module code (rename the class moduel to clsSelect):

' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents

' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
Private oSelectedItems As ObjectCollection

Public Function Pick(filter As SelectionFilterEnum) As Object
    ' Initialize flag.
    bStillSelecting = True

    ' Create an InteractionEvents object.
    Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
    Set oSelectedItems = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Ensure interaction is enabled.
    oInteractEvents.InteractionDisabled = False

    ' Set a reference to the select events.
    Set oSelectEvents = oInteractEvents.SelectEvents

    ' Set the filter using the value passed in.
    oSelectEvents.AddSelectionFilter filter

    ' Start the InteractionEvents object.
    oInteractEvents.Start
    oInteractEvents.StatusBarText = "Select sketch line, or press Esc to cancel selection."
    ' Loop until a selection is made.
    Do While bStillSelecting
        ThisApplication.UserInterfaceManager.DoEvents
    Loop

    Debug.Print "Selected " & oSelectedItems.Count & " entities."
    
    ' Stop the InteractionEvents object.
    oInteractEvents.Stop
    
    ' Clean up.
    Set oSelectEvents = Nothing
    Set oInteractEvents = Nothing
End Function

Private Sub oInteractEvents_OnTerminate()
    ' Set the flag to indicate we're done.
    bStillSelecting = False
End Sub

Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    ' Set the flag to indicate we're done.
    bStillSelecting = True

    Dim i As Long
    For i = 1 To JustSelectedEntities.Count
        oSelectedItems.Add JustSelectedEntities.Item(i)
    Next
End Sub

Private Sub oSelectEvents_OnUnSelect(ByVal UnSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    Dim i As Long
    For i = 1 To UnSelectedEntities.Count
        oSelectedItems.RemoveByObject UnSelectedEntities.Item(i)
    Next
End Sub

 

Hope the above helps.

 

Thanks,

Rocky

Tiffany_Hayden_
Collaborator

Thanks @YuhanZhang !

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea