Create Multi-value parameter with iLogic

Create Multi-value parameter with iLogic

Lance127
Advocate Advocate
15,584 Views
23 Replies
Message 1 of 24

Create Multi-value parameter with iLogic

Lance127
Advocate
Advocate

Is there a way to create a multi-value parameter with ilogic?


Lance W.
Inventor Pro 2013 (PDS Ultimate)
Vault Pro 2013
Windows 7 64
Xeon 2.4 Ghz 12GB
0 Likes
Accepted solutions (1)
15,585 Views
23 Replies
Replies (23)
Message 21 of 24

A.Acheson
Mentor
Mentor

Hi @jltw7PSW2 

Likely this isn't the best post to refer to for adding parameters to a drawing because the parameters is reach from the drawing document and not from the componentdefinition of the part/assembly. Here is the API help for drawing document and parameters object. 

 

Dim drawDoc As DrawingDocument = ThisDoc.Document
Dim drawParams As UserParameters = drawDoc.Parameters.UserParameters
Dim testParam As UserParameter

Try
	testParam = drawParams.Item("TestParam")
Catch 
	testParam = drawParams.AddByValue("TestParam" , "InitialValue", UnitsTypeEnum.kTextUnits)
End Try
	MultiValue.SetList("TestParam", "ASSEMBLY DETAILS", "CONTROL DETAILS", "STEEL DETAILS")

 

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

Sharon_Menachery_782W9QAH4BU8
Participant
Participant

hi i am struggling with creating multi value list 

this is the code i am using for the creating multi value list but the issue is when i am inputting alphabets for my partname it is showing error conversion from string to double not valid

im list As ArrayList                       										
list = MultiValue.List("Part_Name")                      										
Dim msgl As String = vbCrLf & vbCrLf  										
For Each sVal As String In list                                         										
        msgl += sVal & vbCrLf                                         										
		
		
Next                                           										                                                       										
Dim val As String = InputBox("Enter new member name" & msgl, "Adding Val to List", New_Part_name)
If val = 0 Or val Is Nothing Then Exit Sub         										                                              										
                                                 										                                           										
If list.Contains(val) = False Then list.Add(val)  
                                                                										
MultiValue.List("Part_Name") = list

0 Likes
Message 23 of 24

mbrionNYJHY
Explorer
Explorer

@Sharon_Menachery_782W9QAH4BU8 

 

When you do this line:

If val = 0 Or val Is Nothing Then Exit Sub    

I believe it is setting val to be numeric.

Instead, this worked for me:

If val = "0" Or val Is Nothing Then Exit Sub  

 

0 Likes
Message 24 of 24

WCrihfield
Mentor
Mentor

Hi @jltw7PSW2.  There are many ways to do something like this, so you will likely see many different code examples for the same, or very similar task here on this forum, if you do a search in this forum for it.  But here is one possible example code for either creating a new multi-value UserParameter, with a text type value, or to update it if it already exists.  This should work on a part, assembly, or drawing.

 

'get reference to current document
Dim oDoc As Document = ThisDoc.Document
'get access to its parameters - accessed differently in different document types
Dim oParams As Inventor.Parameters = Nothing
If (TypeOf oDoc Is PartDocument) OrElse (TypeOf oDoc Is AssemblyDocument) Then
	oParams = oDoc.ComponentDefinition.Parameters
ElseIf TypeOf oDoc Is DrawingDocument Then
	oParams = oDoc.Parameters
End If
If oParams Is Nothing Then Return 'exit rule if parameters not found
'get the UserParameters collection - this is where we can create a new one, if needed
Dim oUParams As UserParameters = oParams.UserParameters
'make sure the parameter exists before trying to set multiple values to it
Dim oUParam As UserParameter = Nothing
Try 'try to get the existing parameter, by its name
	oUParam = oUParams.Item("TYPE_OF_DWG")
Catch 'what to do if that fails
	oUParam = oUParams.AddByValue("TYPE_OF_DWG", "", UnitsTypeEnum.kTextUnits)
End Try
'now specify the multiple values you want to it to have
Dim oValues() As String = {"ASSEMBLY DETAILS", "CONTROL DETAILS", "STEEL DETAILS" }
'this one causes the document to update after the change
MultiValue.UpdateAfterChange = True
'this one says to set the 'first' value in the new list as the current value of the parameter
MultiValue.SetValueOptions(True, 0)
'now set those values to the parameter
MultiValue.SetList("TYPE_OF_DWG", oValues)
'this line sets this parameter as key
oUParam.IsKey = True

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Edit:  I think I somehow thought that the last reply on the previous page (Message 20) was the newest one (instead of Message 23), and replied to that by mistake, before seeing that there was a second page of replies in this conversation.  🤔😋

Wesley Crihfield

EESignature

(Not an Autodesk Employee)