Set Multivalue Parameter from values Message box outputs

Set Multivalue Parameter from values Message box outputs

bronc3buster842001
Advocate Advocate
1,503 Views
22 Replies
Message 1 of 23

Set Multivalue Parameter from values Message box outputs

bronc3buster842001
Advocate
Advocate

This rule retrieves the info I want from the excel sheet. How do I take the values from the message box and make it into a multivalue parameter.

 

 

 

GoExcel.Open("C:\Users\Brian\Desktop\Book1.xlsx", "Sheet1")

For rowNumber = 5 To 37

	If Voltage = 6.3 Then

		If Not GoExcel.CellValue("B" & rowNumber) = "" Then

			MessageBox.Show(GoExcel.CellValue("A" & rowNumber))

		End If

	End If

Next

GoExcel.Close
0 Likes
1,504 Views
22 Replies
Replies (22)
Message 2 of 23

A.Acheson
Mentor
Mentor

A few steps 

Additions manually:

  1. Create a parameter with the correct units your working with.

Additions By Code:

  1. Create list of either, string, double or Integer depending on what data type your working with. 
  2. Add to the list
  3. Make the multivalue parameter = to the list.

 

Dim List as New List ( Of String)

GoExcel.Open("C:\Users\Brian\Desktop\Book1.xlsx", "Sheet1")

For rowNumber = 5 To 37

	If Voltage = 6.3 Then

		If Not GoExcel.CellValue("B" & rowNumber) = "" Then
   
        List.Add(GoExcel.CellValue("A" & rowNumber))
		
         End If

	End If

Next

GoExcel.Close

MultiValue.List(“ParamName”)​ = List

If you have any questions feel free to ask. The Ilogic help is here which will give you more information. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 23

bronc3buster842001
Advocate
Advocate

Thats works. I was close to having it right.

0 Likes
Message 4 of 23

bronc3buster842001
Advocate
Advocate

Is there a way to also set the default index for the list. The normal options I cant get to work

0 Likes
Message 5 of 23

A.Acheson
Mentor
Mentor

Could you give an example? Have you tried the built in snippet? In my testing I could not get this to function. 

MultiValue.SetValueOptions(True, DefaultIndex := 0)

 

AAcheson_0-1671760568548.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 23

bronc3buster842001
Advocate
Advocate

I wasnt able to get that to work either

 

Also found this bit of code I tried

 

MultiValue.SetValueOptions(True, DefaultIndex := 2)
MultiValue.SetList("T3", "60", "65", "70", "75", "80", "85", "90", “95”, "100")
MultiValue.SetList("T4", 60, 65, 70, 75, 80, 85, 90, 95, 100) 

Dim oParam1 As UserParameter  
oParam1 = ThisDoc.Document.componentdefinition.parameters.item("T3")
oParam1.ExpressionList.SetExpressionList(oParam1.ExpressionList.GetExpressionList(), True, 8)

Dim oParam2 As UserParameter  
oParam2 = ThisDoc.Document.componentdefinition.parameters.item("T4")
oParam2.ExpressionList.SetExpressionList(oParam2.ExpressionList.GetExpressionList(), True, 4)
Message 7 of 23

A.Acheson
Mentor
Mentor

The expression list method via the API works. The ilogic version only works on a string value and only sometimes for me. Here is the explanation. Maybe someone can indicate why it doesn't work. Perhaps it needs very specific criteria. 

 

MultiValue.SetValueOptions(True, DefaultIndex := 0)

Forces the parameter to have a value which is in its multi-value list. If you then change the multi-value list, it also sets the current value of the parameter to one of the values in the list. This function does not change the value if it is found in the new list.

DefaultIndex := 0

This applies only to Text parameters. If the current parameter value is not in the new list, the parameter is set to the first value (Index 0) in the list. You can choose a value other than 0. This has no effect on numeric parameters. For numeric parameters, the value chosen from the list will be the one that is closest to the current value.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 23

bronc3buster842001
Advocate
Advocate

I wasnt able to get the expression list method via the API to work.

0 Likes
Message 9 of 23

A.Acheson
Mentor
Mentor

This is all you need to set the I dex of the parameter. 

Dim oParam1 As UserParameter  
oParam1 = ThisDoc.Document.componentdefinition.parameters.item("T3")
oParam1.ExpressionList.SetExpressionList(oParam1.ExpressionList.GetExpressionList(), True, 8)

If this doesn't work just post up a screenshot of the more info if an error exist. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 10 of 23

bronc3buster842001
Advocate
Advocate

If works but doesnt allow me to select any other value from the list

0 Likes
Message 11 of 23

A.Acheson
Mentor
Mentor

That code will only select which one you want default at a moment in time like when adding a new parameter etc it isnt a user interface for the parameter. If you want the user to select and set the parameter by code you can use an inputlist box or use the built in parameter box or put the parameter in a form.

Dim value as Integer = InputListBox("Prompt",MultiValue.List("T5"), defaultEntry, Title := "Dialog Title", ListPrompt := "List Prompt")
 
T5 = value
MessageBox.Show(T5)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 12 of 23

bronc3buster842001
Advocate
Advocate

I attached a part file in my last post. I have the 2 parameters I want the user to select in a form.

0 Likes
Message 13 of 23

A.Acheson
Mentor
Mentor

I don't have 2022 so can't open the file. Here is the instructions . No code needed to manually set up the form. Use a global form if you want the form  for multiple files. 

AAcheson_0-1671845558935.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 23

bronc3buster842001
Advocate
Advocate

That is what I have.

0 Likes
Message 15 of 23

bronc3buster842001
Advocate
Advocate

This gives me an error

Dim List As New ArrayList
MultiValue.SetValueOptions(True, DefaultIndex := 0)

GoExcel.Open("E:\Inventor\Electronic Parts\Capacitors\_Configs\Aluminum Electrolytic Capacitor.xlsx", "Sheet1")

Select Case Voltage

	Case = 6.3
		For rowNumber = 5 To 37
			If Not GoExcel.CellValue("B" & rowNumber) = "" Then
				List.Add(GoExcel.CellValue("A" & rowNumber) & "uF")
			End If

			MultiValue.List(“Cap”) ​= List

			If Cap = GoExcel.CellValue("A" & rowNumber) & "uF" Then
				DiaLen = GoExcel.CellValue("B" & rowNumber)
			End If

 

bronc3buster842001_0-1671846716956.png

 

0 Likes
Message 16 of 23

A.Acheson
Mentor
Mentor

I am not certain of your design intent but you can get more information about the error with the more info tab

AAcheson_0-1671853438909.png

If you use the parameter function you will find that the parameters update while the rule runs. It may help how the rule functions.

Parameter.UpdateAfterChange = True

Dim List As New ArrayList

GoExcel.Open("E:\Inventor\Electronic Parts\Capacitors\_Configs\Aluminum Electrolytic Capacitor.xlsx", "Sheet1")

Select Case Voltage

	Case = 6.3
		For rowNumber = 5 To 37
			If Not GoExcel.CellValue("B" & rowNumber) = "" Then
				List.Add(GoExcel.CellValue("A" & rowNumber) & "uF")
			End If

			MultiValue.List("Cap") ​= List

			If Parameter("Cap") = GoExcel.CellValue("A" & rowNumber) & "uF" Then
				Parameter("DiaLen") = GoExcel.CellValue("B" & rowNumber)
			End If

		Next
End Select

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 17 of 23

bronc3buster842001
Advocate
Advocate

This is from more info on the error

 

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ExpressionList.SetExpressionList(String[]& ExpressionList, Boolean ChangeCurrentValue, Int32 CurrentValueIndex)
at iLogic.CadExpressionList.SetExpressionList(Parameter param, IList valueList, Boolean changeExpression, Int32 defaultIndex)
at iLogic.MultiValueParam.SetListToParam(Parameter param, IList vList)
at ThisRule.Main() in rule: Test_Copy_Copy, in document Part1.ipt:line 17
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 18 of 23

bronc3buster842001
Advocate
Advocate

Here is my form. Basically when you select a voltage it populates the cap values. But I would like it to set a default value.

 

bronc3buster842001_1-1671854527952.png

 

 

0 Likes
Message 19 of 23

A.Acheson
Mentor
Mentor

Ok I think I get your intent now. When you populate the blank parameter "Cap" no initial value is being set. 

AAcheson_0-1671896523135.png

So to do this after the parameter receives the list to form the multivalue parameter, use Method 1/2 in the below. In short you are just setting the parameter equal to a value in the list. 

 

 

 

Parameter.UpdateAfterChange = True

Dim List As New ArrayList

GoExcel.Open("C:\Users\aacheson\Desktop\WFH\Samples\VoltageTest.xlsx", "Sheet1")

Select Case Voltage

	Case = 6.3
		For rowNumber = 5 To 37
			If Not GoExcel.CellValue("B" & rowNumber) = Nothing Then
				List.Add(GoExcel.CellValue("A" & rowNumber) & "uF")
			End If
			MultiValue.List("Cap") ​= List
			If Parameter("Cap") = GoExcel.CellValue("A" & rowNumber) & "uF" Then
				Parameter("DiaLen") = GoExcel.CellValue("B" & rowNumber)
			End If

		Next
		
		'Method 1 Set Default by index of parameter starting from 0
		Dim oParam1 As UserParameter = ThisDoc.Document.componentdefinition.parameters.item("Cap")
		oParam1.ExpressionList.SetExpressionList(oParam1.ExpressionList.GetExpressionList(), True, 3)'0,1,2,3
		MessageBox.Show(oParam1.Value, "Title")
		
		'Method 2 Set Default by Setting the parameter =  a value
		Parameter("Cap") = GoExcel.CellValue("A" & 8) & "uF"
		MessageBox.Show(Parameter("Cap"), "Title")

End Select

 This line will not work as it is designed to work when the list changes but it cannot be used at the beginning because there is no list to change. It is only being created. It cannot be used after each value is added because if you had a index of 8 and only 7 values added it will error out.  So it must be placed after the list is complete.

	MultiValue.SetValueOptions(True, DefaultIndex := 0)

 Here is a reworked example and how to use the built in Index setting. There was too many operations happening in the original for loop to make it work. 

Parameter.UpdateAfterChange = True

Dim List As New ArrayList

Dim FileName As String = "E:\Inventor\Electronic Parts\Capacitors\_Configs\Aluminum Electrolytic Capacitor.xlsx"

GoExcel.Open(FileName, "Sheet1")

Select Case Voltage

	Case = 6.3
		For rowNumber = 5 To 37
				If Not GoExcel.CellValue("B" & rowNumber) = Nothing Then
					List.Add(GoExcel.CellValue("A" & rowNumber) & "uF")
				End If
		Next
			
		'Set List and Intitial value
		MultiValue.SetValueOptions(True, DefaultIndex := 1)
		
		Parameter("Cap") = "0uF" ' Add a value not in the list to ensure the list changes when initialized this will trigger the Set Value Options line to work
		
		MultiValue.List("Cap") ​= List
	
		
		'[Match The DiaLen Parameter To Cap Parameter
		
		Dim CapExcel As String = Left(Parameter("Cap"), (Len(Parameter("Cap")) -2))'Because excel value is not matching parameter, we need to convert to excel value
		'MessageBox.Show(CapExcel, "Parameter to CapExcel Conversion")
		
		
		GoExcel.TitleRow = 1
		
		i = GoExcel.FindRow(FileName, "Sheet1", "Cap", "=", CapExcel)
		
		If i = -1 Then MessageBox.Show("No value found or blank cell found! Exiting", "iLogic Find Row Warning") : Return ' Ensure no blank cells Or find row will Return -1 Or Error message cannot find Object.
		
		Parameter("DiaLen") = GoExcel.CurrentRowValue("DiaLen")
']
		
End Select

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 20 of 23

bronc3buster842001
Advocate
Advocate

I can get it to set the default value. It just doesnt allow me to change it it the list

0 Likes