Add Description next to arraylist item?

Add Description next to arraylist item?

bbrumfield
Advocate Advocate
720 Views
8 Replies
Message 1 of 9

Add Description next to arraylist item?

bbrumfield
Advocate
Advocate

I have a situation where I've created a rule to return the a material stock code from an ArrayList, the problem is I also need to see the stock code description to make the correct selection. 

Dim oDoc As Document = ThisDoc.Document
Dim CustTypeCRS As New ArrayList
CustTypeCRS.Add("ME-CRS-0006")'22GA, Sheet, Cold Rolled Steel, 60.00 x 120.00
CustTypeCRS.Add("ME-CRS-0009")'16GA, Sheet, Cold Rolled Steel, 60.00 x 120.00
CustTypeCRS.Add("Me-CRS-0010")'20GA, Sheet, Cold Rolled Steel, 60.00 x 120.00
CustTypeCRS.Add("ME-CRS-0011")'18GA, Sheet, Cold Rolled Steel, 60.00 x 120.00
CustTypeCRS.Add("ME-CRS-0013")'14GA, Sheet, Cold Rolled Steel, 60.00 x 120.00

Dim oSelMaterialStockCode As String = InputListBox("Select Material Stock Code", CustTypeCRS, oMaterialStockCode, Title := "CRS Sheet Selection", ListName := "CRS Sheet Stock Code")
'if this custom property doesn't exist, this next line will also crete it if needed (no error shown)
iProperties.Value("Custom", "Material Stock Code") = oSelMaterialStockCode
0 Likes
Accepted solutions (3)
721 Views
8 Replies
Replies (8)
Message 2 of 9

dalton98
Collaborator
Collaborator

Edit: This is not what you were asking lol

I would add another value to list for none

CustTypeCRS.Add("none")

 

Then before the imputlistbox put this

Try
oMaterialStockCode = iProperties.Value("Custom", "Material Stock Code")
Catch
oMaterialStockCode = "none"
End Try

 Also you could just have the tile of the list be the current stock code instead of "Select Material Stock Code". Then you wouldn't have to add another list value and the title would either be blank or give the previous value.

Hope this is what you were asking.

0 Likes
Message 3 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @bbrumfield,

 

You can add them together with a delimiter (in this case a vertical bar "|") and then use the Split function to create an array from the selection, and only use the part number portion of the array for the iproperty value. See example below.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oDoc As Document = ThisDoc.Document
Dim CustTypeCRS As New ArrayList
CustTypeCRS.Add("22GA, Sheet, Cold Rolled Steel, 60.00 x 120.00 | ME-CRS-0006")
CustTypeCRS.Add("16GA, Sheet, Cold Rolled Steel, 60.00 x 120.00 | ME-CRS-0009")
CustTypeCRS.Add("20GA, Sheet, Cold Rolled Steel, 60.00 x 120.00 | Me-CRS-0010")

Dim oSelMaterialStockCode As String = InputListBox("Select Material Stock Code", 
	CustTypeCRS, oMaterialStockCode, Title := "CRS Sheet Selection", _
	ListName := "CRS Sheet Stock Code")

sSplit = Split(oSelMaterialStockCode, "|")
oDesc = sSplit(0) 
oPN = sSplit(1) 

'if this custom property doesn't exist, this next line will also create it if needed (no error shown)
iProperties.Value("Custom", "Material Stock Code") = oPN

MsgBox(iProperties.Value("Custom", "Material Stock Code") )

 

EESignature

0 Likes
Message 4 of 9

petr.meduna
Advocate
Advocate
Accepted solution

Just add the description to array list and then separate the selection via char you choose. For example:

Dim oDoc As Document = ThisDoc.Document
Dim CustTypeCRS As New ArrayList
CustTypeCRS.Add("ME-CRS-0006/22GA, Sheet, Cold Rolled Steel, 60.00 x 120.00")
CustTypeCRS.Add("ME-CRS-0009/16GA, Sheet, Cold Rolled Steel, 60.00 x 120.00")
CustTypeCRS.Add("Me-CRS-0010/20GA, Sheet, Cold Rolled Steel, 60.00 x 120.00")
CustTypeCRS.Add("ME-CRS-0011/18GA, Sheet, Cold Rolled Steel, 60.00 x 120.00")
CustTypeCRS.Add("ME-CRS-0013/14GA, Sheet, Cold Rolled Steel, 60.00 x 120.00")

Dim oSelMaterialStockCode As String = InputListBox("Select Material Stock Code", CustTypeCRS, oMaterialStockCode, Title := "CRS Sheet Selection", ListName := "CRS Sheet Stock Code")
Dim oSplit() As String = Split(oSelMaterialStockCode, "/")
iProperties.Value("Custom", "Material Stock Code") = oSplit(0)
Message 5 of 9

bbrumfield
Advocate
Advocate

Works Perfectly!  

 

Thanks,

 

Brent

0 Likes
Message 6 of 9

Michael.Navara
Advisor
Advisor
Accepted solution

More sophisticated solution is to use custom object (class) for items. See the following sample code

 

 

Sub Main
	Dim items As New List(Of ListItem)
	items.Add(New ListItem("1", "One") )
	items.Add(New ListItem("2", "Two") )
	items.Add(New ListItem("3", "Three"))
	
	Dim selectedItem = InputListBox("Select value", items)
	Logger.Debug(selectedItem.Value)
End Sub


Class ListItem
	Public Sub New(value As String, displayName As String)
		Me.Value = value
		Me.DisplayName = displayName
	End Sub
	
	Public Property Value As String
		
	Public Property DisplayName As String
		
	Public Overrides Function ToString() As String
		Return DisplayName
	End function
End Class
	

 

0 Likes
Message 7 of 9

bbrumfield
Advocate
Advocate
Hi Michael,

Thank you, I will test. I think from what I see and please correct me if I'm wrong. The attached code appears to allow the rule to be selected multiple times creating a new custom for ea.?

Thanks,


Brent F. Brumfield
Director of Engineering
P: (513) 385-0555
M: (513) 309-6643
bbrumfield@arscometals.com
www.arscomfg.com

[cid:image001.png@01D84F1D.09510460]


0 Likes
Message 8 of 9

bbrumfield
Advocate
Advocate

Hi Michael,

 

I tested the code you attached and must be doing something incorrectly, the code ran without error but produced no results. 

 

Thanks,

 

Brent

0 Likes
Message 9 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @bbrumfield ,

 

That example uses the iLogic Logger to show the result. You can use this modified example to see the result in a message box.

 

More about the iLogic Logger, if interested:

https://knowledge.autodesk.com/support/inventor/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/Inve...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main
	Dim oList As New List(Of ListItem)
	oList.Add(New ListItem("1", "One") )
	oList.Add(New ListItem("2", "Two") )
	oList.Add(New ListItem("3", "Three"))
	
	Dim selectedItem = InputListBox("Select value", oList)
	'Logger.Debug(selectedItem.Value)
	MsgBox(selectedItem.Value,,"iLogic")
End Sub


Class ListItem
	Public Sub New(value As String, displayName As String)
		Me.Value = value
		Me.DisplayName = displayName
	End Sub
	
	Public Property Value As String		
	Public Property DisplayName As String
		
	Public Overrides Function ToString() As String
		Return DisplayName
	End Function
End Class

  

EESignature

0 Likes