iLogic: Let user select multiple objects at once (with selection rectangle)

iLogic: Let user select multiple objects at once (with selection rectangle)

j.pavlicek
Collaborator Collaborator
2,793 Views
6 Replies
Message 1 of 7

iLogic: Let user select multiple objects at once (with selection rectangle)

j.pavlicek
Collaborator
Collaborator

Hello,
is possible to pause iLogic and let user select multiple objects with selection rectangle?

 

I know about CommandManager.Pick Method, but this allows me to pick only single object at once (I'm talking about hundreds of objects in selection). Also I'm able to get this amount from Document.SelectSet, but I don't like a neccessity that SelectSet has to be selected before iLogic is started - it's unintuitive.

 

Thanks for suggestions.

 

 

 

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Accepted solutions (1)
2,794 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @j.pavlicek 

You'll have to use SelectEvents. Try this example. It'll return a ObjectsEnumerator of the selected occurrences (I used kAssemblyLeafOccurrence as selectionfilter in the example). Then to show that it has actually returned the selected objects it'll give you the count in a messagebox 🙂

 

Sub Main
	Dim oSelect As New clsSelect
	oSelect.WindowSelect(ThisApplication)
	MsgBox(oSelect.SelectedObjects.Count)
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 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
		bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True
		oInteractEvents.StatusBarText = "Select component occurrences. Esc to finish."
		oInteractEvents.Start()
		While stillSelecting
			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
	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
	End Sub
End Class
Message 3 of 7

parth.zala
Explorer
Explorer

Hello @JhoelForshav ,

 

I tried this code, it allow me to select and shows the right count, but when I try to use the selected entities, code shows an error. Error occurs while saving iLogic code, so it never runs. I added these two lines in the sub main. 

 

	obj = oSelect.SelectedObjects.Item(0)
	MessageBox.Show(TypeName(obj))

 

Thank you,

Parth

0 Likes
Message 4 of 7

j.pavlicek
Collaborator
Collaborator

 @parth.zala 

I see this problems:

obj is not declared

Items in a Collection are 1 based (Item(0) doesn't exist)

 

And your main problem is MessageBox.Show(). This uses namespace from System.Windows.Forms which also contain type View. You must specify which View is meant in affected lines (its Inventor.View or System.Windows.Form.View?)

 

Solution:

Avoid using of System.Windows.Forms by ommiting MessageBox (Use MsgBox() instead).

OR

Fully specify View on affected lines (View -> Inventor.View)

 

More info: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/namespaces



Inventor 2022, Windows 10 Pro
Sorry for bad English.
Message 5 of 7

parth.zala
Explorer
Explorer
Thanks a lot. It worked. using MsgBox() solved the problem.

0 Likes
Message 6 of 7

andrescastellanosint
Contributor
Contributor

Hello, excusme How select multiple objects without to use ESC. I need to use the command join. Thanks

0 Likes
Message 7 of 7

andrescastellanosint
Contributor
Contributor

Select multiple objects into part with Ilogic and  I and thus be able to edit. Thanks

0 Likes