OnSelect Events for a WinForm - SketchLines

OnSelect Events for a WinForm - SketchLines

Tiffany_Hayden_
Collaborator Collaborator
562 Views
9 Replies
Message 1 of 10

OnSelect Events for a WinForm - SketchLines

Tiffany_Hayden_
Collaborator
Collaborator

I'm starting a OnSelect Event on a form load. My wish is to when the user is selecting a sketchline in the model there will be interaction with the form eventually. But I ran into a road block with the OnSelect Event. I have found that it keeps the selection as the selection happens. For example if they select one line and then select another it keeps the previous lines selection and the one that was just selected. I don't think this is the intention so I'm assuming I'm not handling the event correctly. Any help would be appreciated. I tried to use the clear the select set but it has not effect on the onselect event. 

 

Class Properties 

    Private formInteractionEvents As Inventor.InteractionEvents
    Private formSelectEvents As Inventor.SelectEvents

 

Load

    Private Sub ConfigureForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        formInteractionEvents = g_inventorApplication.CommandManager.CreateInteractionEvents()
        formSelectEvents = formInteractionEvents.SelectEvents

        AddHandler formSelectEvents.OnSelect, AddressOf SelectEvents_OnSelect

        formInteractionEvents.Start()
End Sub

 

OnSelect Event

    Public Sub SelectEvents_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View)

        Dim currentSelectSet As SelectSet = g_inventorApplication.ActiveDocument.SelectSet

        Dim selectedSketchLine As SketchLine = JustSelectedEntities _
                                                .OfType(Of Object)() _
                                                .Where(Function(entity) TypeOf entity Is SketchLine) _
                                                .Select(Function(entity) CType(entity, SketchLine)) _
                                                .FirstOrDefault()



        currentSelectSet.Clear()

        'RemoveHandler _selectEvents.OnSelect, AddressOf SelectEvents_OnSelect
        ''_interactionEvents = Nothing
    End Sub

 

 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Accepted solutions (1)
563 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Have you tried setting the SelectEvents.SingleSelectEnabled property's Value to True yet?  I believe that should prevent multiple entities being selected at the same time, if that is one of your goals.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Tiffany_Hayden_.  Have you attempted to apply the change I mentioned in my last response yet?  To use it, within your block of code labeled 'Load', on the next line after where you set the value of your 'formSelectEvents' variable, try inserting this line of code:

formSelectEvents.SingleSelectEnabled = True

With that set to True, it should only allow one item to be in the 'SelectedEntities' at a time, and when something new is selected, it should replace the previously selected item.

 

And if that does not meet your needs, then down within your 'OnSelect Event' block of code, you can try using one or both of the methods available to us from the SelectEvents object:

SelectEvents.RemoveFromSelectedEntities 

SelectEvents.ResetSelections 

...because the SelectEvents.SelectedEntities property (which holds the running selection set for the event) is ReadOnly.

I am not sure what all you may have going on while in selection mode, but you may also want to 'handle' the SelectEvents.OnPreSelect Event for more control over visual feedback / highlighting, and/or the SelectEvents.OnUnSelect Event.  And you may even want to throw in the InteractionEvents.OnSuspend & InteractionEvents.OnResume events, if your selection mode may need to be interrupted by intermediate actions.  You could also incorporate a 'MiniToolBar' using the InteractionEvents.CreateMiniToolbar and handlers for the events of that object, to give the user even more control over when to end or cancel out of that mode (other than using the Escape key).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 10

Tiffany_Hayden_
Collaborator
Collaborator

Awesome! I will try those out. They seem very promising. Appreciate your help.  On a side not have you ever dealt with OnSelect events and using a picker from the command manager and managing that? Do they step on each other? @WCrihfield Let me know! Thanks

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 5 of 10

WCrihfield
Mentor
Mentor

No, I do not recall ever trying to use both at the same time.  I believe I did make myself a custom alternative to the Pick function, using the SelectEvents and related tools, but never attempted utilizing two different selection tools in the save overall routine before.  So I am not sure if one would interfere with the other.  Seems to me like it is usually view related commands like zoom, pan, orbit and such that will cause some other 'commands / routines' to pause/suspend when the start, then resume when they are finished.  Not sure about other types of commands suspending/resuming stuff.  Good luck with that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 10

Tiffany_Hayden_
Collaborator
Collaborator

Okay. Sounds good. Thanks for your help! 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 7 of 10

Curtis_Waguespack
Consultant
Consultant

@Tiffany_Hayden_ 

 

edit: oh wait,  I thought it was using the command manager pick, but now after posting I don't see that it does.

 

Here's an example I had on hand that uses the pick and select events together

( I probably got this, at least in part, from this forum, so thanks! to whoever posted it originally)

 

You can uncomment the windows select line and change the single select to see how it works.

 

This is for assembly components, but you can modify it for sketch lines.

 

You can just drop it in an iLogic rule to test it.

 

Hope that helps.

 

Sub Main

	Dim oSelect As New clsSelect
	oSelect.WindowSelect(ThisApplication)

	comps = oSelect
	For Each comp As ComponentOccurrence In oSelect.SelectedObjects
		Dim oDef As PartDocument
		oDef = comp.Definition.Document
		'do something with selection here
	Next
End Sub

Class clsSelect
	Private WithEvents oInteractEvents As InteractionEvents
	Private WithEvents oSelectEvents As SelectEvents
	Private bTooltipEnabled As Boolean
	Private ThisApplication As Inventor.Application
	Public SelectedObjects As ObjectsEnumerator
	Private stillSelecting As Boolean = True
	Public i As Integer
	Public Msg As String

	Public Sub WindowSelect(oApp As Inventor.Application)

		ThisApplication = oApp
		oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
		oInteractEvents.InteractionDisabled = False

		oSelectEvents = oInteractEvents.SelectEvents
		oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter)
		'oSelectEvents.WindowSelectEnabled = true
		oSelectEvents.SingleSelectEnabled = True

		bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True

		oInteractEvents.Start()

		While stillSelecting
			If oSelectEvents.SingleSelectEnabled = True Then
				oInteractEvents.StatusBarText = "Select a components. Press Esc to finish."
			Else
				oInteractEvents.StatusBarText = "Select components. Shift+Click to unselect. Esc to finish. ( count: " & i & " )"
			End If
			ThisApplication.UserInterfaceManager.DoEvents()
		End While
	End Sub

	Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled
		oSelectEvents = Nothing
		oInteractEvents = Nothing
		stillSelecting = 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) Handles oSelectEvents.OnSelect
		SelectedObjects = oSelectEvents.SelectedEntities
		i = SelectedObjects.Count
	End Sub

	Private Sub oSelectEvents_OnUnSelect(UnSelectedEntities As ObjectsEnumerator, SelectionDevice As SelectionDeviceEnum,
		ModelPosition As Point, ViewPosition As Point2d, View As View) Handles oSelectEvents.OnUnSelect
		SelectedObjects = oSelectEvents.SelectedEntities
		i = SelectedObjects.Count
	End Sub
End Class

 

EESignature

Message 8 of 10

Tiffany_Hayden_
Collaborator
Collaborator

@Curtis_Waguespack You say on hand like you had that in your pocket! haha jk. Thanks so much for the example. Appreciate it. I was fighting pretty good with my form yesterday hopefully with these tips I can move it forward. 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 9 of 10

Curtis_Waguespack
Consultant
Consultant

well it's a digital pocket 😁 ... (I keep a stash of code examples so I don't have to reinvent the wheel )

EESignature

0 Likes
Message 10 of 10

Tiffany_Hayden_
Collaborator
Collaborator

Digital pockets are the best! Have a great day!

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes