MultiSelectListBox (based on iLogic's InputListBox)

MultiSelectListBox (based on iLogic's InputListBox)

WCrihfield
Mentor Mentor
2,227 Views
9 Replies
Message 1 of 10

MultiSelectListBox (based on iLogic's InputListBox)

WCrihfield
Mentor
Mentor

Hi folks.  This is not really a question, just an offering, of sorts.  I've known about this ability for some time now, but figured it was time to post it publicly here on the Inventor iLogic, API & VBA Forum, since we can no longer post them to our own knowledge base articles, and I do not want to operate my own Blog about this stuff.  Just as the title indicates, there is a way to 'sort of' change the functionality of an InputListBox, so that you can select multiple items at once.  No more having to use a regular InputListBox within a loop, and only being able to select a single item each time until you escape the loop.

 

How I discovered this:

When you type in "InputListBox" into an iLogic rule, you see that it originates from something called "RunDialogs".  If you type "RunDialogs" directly into an iLogic rule, you see that it represents a Module (Link, Link) within "Autodesk.iLogic.RunTime".  When you type "Autodesk.iLogic.RunTime" directly into an iLogic rule, you can see that it represents a Namespace (Link, Link).  With that in mind, I started from that directly typed in "Autodesk.iLogic.RunTime" (unquoted), I could see many other things under it.  By the way, you may also notice "GenericRadioButtonBox" listed in there too, which as you might have guessed, is the similar way to get more control over an iLogic InputRadioBox.  Those are usually created from the ""Autodesk.iLogic.RunTime.RunDialogs" Module, but you can initiate your own, using the similar path mentioned above.  The obvious advantage here is that you can access the actual System.Windows.Forms.Form Type object that these utilize, and therefore you can further manipulate them, as you wish.  Of course you could just create your own Windows Form directly within the iLogic rule, but that may require a lot more code (and knowledge about that extra code).

 

Anyways, here is an example of the code used to create a custom Function I have used directly within iLogic rules, that presents an InputListBox, but allows you to select multiple items.  You will notice however, the 'Return' Type being an IEnumerable(Of Object), since the InputListBox returned a single Object.  I also did not include the last two options Height & Width, because I have never used them, and have never seen anyone else use them, but feel free to copy this and create your own variations that to include them.  Or maybe don't even use it as a custom Function, and just use the Function's interior code directly if you want, but the input parameters are in a different order, not that it matters.

Sub Main
	Dim oList As New List(Of String) From {"Option 1", "Option 2", "Option 3" }
	Dim Selected As IEnumerable(Of Object) = MultiSelectListBox("Select Some", oList, Nothing, "Multi-Select InputListBox", "My List")
	If Selected.Count = 0 Then
		MessageBox.Show("Nothing was selected from the list.", "None Selected",MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	Else
		For Each Item In Selected
			MessageBox.Show("You selected:  " & Item.ToString, "Selected", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
		Next
	End If
End Sub

Function MultiSelectListBox(Optional Instructions As String = vbNullString, Optional Items As IEnumerable = Nothing,
Optional DefaultValue As Object = Nothing, Optional Title As String = vbNullString, Optional ListName As String = vbNullString) As IEnumerable(Of Object)
	Using oILBD As New Autodesk.iLogic.Runtime.InputListBoxDialog(Title, ListName, Instructions, Items, DefaultValue)
		Dim oLB As System.Windows.Forms.ListBox = oILBD.Controls.Item(0).Controls.Item(2)
		oLB.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
		Dim oDlgResult As System.Windows.Forms.DialogResult = oILBD.ShowDialog()
		Dim oSelected As IEnumerable(Of Object) = oLB.SelectedItems.Cast(Of Object)
		Return oSelected
	End Using
End Function

This is why you could never find an InputListBox or InputRadioBox anywhere else within the general vb.net stuff...because they are unique to the iLogic ApplicationAddIn, and its associated resources.

 

If you like this content, or if this helped you out in some way, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

2,228 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

By the way, just to give credit where credit is due...

Although I had explored into similar aspects & resources before, I was inspired to dig further into these uniquely iLogic forms by a post here on this forum a while back by @Curtis_Waguespack at this thread that I participated in.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/delete-forms-with-rule/m-p/11187072/... 

Kudos to Curtis for being an inspiration to me and many others over the years. 👍

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10

WCrihfield
Mentor
Mentor

Just pointing to another example of this technique, where just the internal code portion of the 'MultiSelectListBox' Function is being used within a simple consolidated rule, without having to include terms like 'Sub Main' & 'End Sub', then calling the whole external Function.  In situations where you only need to use the list once, doing it this way will be more efficient.  However, please note that in that example, I know ahead of time that I am working with Strings (not some other type of Objects), so I am directly casting the result to an IEnumerable(Of String), then on to a List(Of String), instead of an IEnumerable(Of Object) as the main function was designed to do, since this is likely the most popular use of a list like this anyways.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/multi-select-helpp/m-p/12053164/high... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 10

Maxim-CADman77
Advisor
Advisor

Can you please clarify why those Control indexes (0 and 2) are used in line 16 and whether index-based references can be replaced with something more meaningful (human-readable)?

PS:

I believe System.Windows.Forms.SelectionMode.MultiExtended would not make the experienced user happy as it does not support popular modification with holding Shift-key (add/remove several contiguous options). Thus MultiExtended would be my personal choice for SelectionMode.

Please vote for Inventor-Idea Text Search within Option Names

Message 5 of 10

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.

As for why those specific Index numbers, instead of some other more meaningful specs...

When I did my initial research into the InputListBoxDialog object that I learned we could create, I used some custom inspection code to look at its immediate properties & methods, then also to recursively iterate through each Control within it, getting their Name, TypeName, HasChildren, and so on.  Turns out that it only has one direct Control (at Item(0)), and it is a TableLayoutPanel type Control that was named "tableLayoutPanel1", and it had 5 child controls.  When iterating a System.Windows.Forms.Control.ControlCollection type collection using its Item() property, it only allows Integer specification for the Index of each Control.  Among those 5 child controls was a Label type Control named "Label1" (no children), a Button type Control named "OK_Button" (no children), a ListBox type Control named "ListBox1" (no children), a RichTextBox type Control named "RichTextBox1" (no children), and another Label type Control named "Label2" (no children)...in that order, starting from Item(0).  I know that I wanted to access the ListBox type object, which was Item(2).

 

As for why I chose that specific selection mode...

I simply was not super familiar with that MultiExtended variation yet, so I was not super sure if I would need to include extra code to support its added functionality or not at that time, so I opted for the simper one, and it seemed to be working exactly as I wanted it to.  I saw later that the Ctrl and Shift keys had no effect when using the simple mode, but kept it simple in most cases, because most of my lists were fairly short.  I have used the extended mode a couple times in one or two places where longer lists may be presented and a range of values are acceptable.

Thanks for pointing that out though.  Its good for folks to see more ways to modify it to suit their individual needs.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 10

emanuel.c
Collaborator
Collaborator

@WCrihfield 

 

Pardon my ignorance, but how can I use the result? For example in a Select Case or something. If Item 1 was selected, do this. If Item 1 and 3 do that etc. ?

 

Thank you for the code! It would be very useful!

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor

Hi @emanuel.c.  The options for how this could be used are wide open (too numerous to list here).

 

The entries in the list could be:

  • Names of sheets in a drawing with a lot of sheets, and you only want to print or export selected sheets.
  • Names of all user parameters, or custom iProperties, where you want to choose which ones to:  (copy to or from another document) , (set to key or exported) , (export to Excel with a custom routine) , (show the values of in a message) , etc.
  • Names of all locally or globally available SketchedSymbols, so you can choose all the ones you want to copy or insert into your current drawing from a template or global library
  • Names of materials or appearances (or drawing object styles of a specific type) that you want to copy multiple of from the global library into your local document, for use later.
  • The names of multiple file formats that are common for exporting Inventor files out to, so you can choose which ones you need, then a code can run a pre-defined set of files through all the appropriate code routine's associated with exporting to those file types.

How you use the single or multiple selections, all depends on what you actually want/need to do with them.

A Select Case statement does not make much sense so me at the moment, because that is for checking one variable, and reacting to it in multiple possible ways, depending on its value.  I guess since this routine does return a single variable, that variable could be reacted to in multiple ways, but I usually use a regular 'If...Then' statement for that.  Where a Select Case statement is really advantageous is when some of the individual Case lines can be used for reacting to multiple possible values of the variable...less iterations that way compared to an If...ElseIf...End If statement.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 10

emanuel.c
Collaborator
Collaborator

Thank you for that explanation!

 

I would like to use it to trigger other functions. For example:

  • If "Option 1" was selected call "Function 1".
  • If "Option 2" -> call "Function 2"
  • If "Option 1" and "Option 2" -> call "Function 1" then "Function 2"

But I don't know how to capture what was selected in the Input List. Or what does the variable "Selected" return?

 

emanuelc_1-1727458680800.png

 

 

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

Fair question.  I will attach two text files to this reply.  Each will contain code for a different iLogic rule example for testing this function with.  It is OK to modify this Function in whatever way suits your needs best, as long as it still works after the modifications. 😉  With that in mind, I modified it to return an List(Of String) instead of an IEnumerable(Of Object), because we are pretty much always going to be using it for Strings anyways, and that Type is easy to work with and use, even if it might not be the most efficient.  I also changed it so that if none of the options are selected, it will return Nothing, instead of an empty List, but I am not sure if you will always want it to be that way.  The one example just shows a message, for quick testing and tweaking.  The other example contains 3 simple Functions that each show a message when ran, for proof of functionality.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

emanuel.c
Collaborator
Collaborator

Thank you so much! That works beautifully!

0 Likes