Hi @chris, see this example.
Sub Main
oObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim ParamList As New ArrayList
' Name | Value | Unit | Comment
'_____________Add Parameter Below This Line _________________________
'Parameter Group 1
oObjectCollection.Clear
ParamList.Clear
ParamList.Add("User_Parameter_001|9.125|in|Notes")
ParamList.Add("User_Parameter_002|8|deg|Notes")
ParamList.Add("User_Parameter_003|9|ul|Notes")
'send strings to sub routine
For Each ParamString In ParamList : CreateParams(ParamString) : Next
Add_Parameter_Group("Param Group 1")
'Parameter Group 2
oObjectCollection.Clear
ParamList.Clear
ParamList.Add("User_Parameter_004|9.125|in|Notes")
ParamList.Add("User_Parameter_005|8|deg|Notes")
ParamList.Add("User_Parameter_006|9|ul|Notes")
'send strings to sub routine
For Each ParamString In ParamList : CreateParams(ParamString) : Next
Add_Parameter_Group("Param Group 2")
iLogicVb.UpdateWhenDone = True
End Sub
'variables shared among subs
Dim oObjectCollection As ObjectCollection
Sub CreateParams(ParamString As String)
'split each string using the | as the split character
StringArray = Split(ParamString, "|")
ArrayCount = UBound(StringArray)
If ArrayCount < 3 Then
MsgBox(ParamString & vbLf & "Only " & ArrayCount & " ' | ' seperator chrs in string" & vbLf & "Expected 3, you might need to add one to the end", , "ilogic")
Exit Sub
End If
ParameterName = StringArray(0) 'first item in array
ParameterValue = StringArray(1) 'second item in array
ParameterUnit = StringArray(2) 'etc
ParameterComment = StringArray(3) 'etc
'set up conversion factors
Dim DocumentUnitsOfMeasure As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Cnvt_cm_to_in = DocumentUnitsOfMeasure.ConvertUnits(1, UnitsTypeEnum.kInchLengthUnits, UnitsTypeEnum.kCentimeterLengthUnits) 'cm to inch (2.54)
Cnvt_Rad_to_Deg = DocumentUnitsOfMeasure.ConvertUnits(1, UnitsTypeEnum.kDegreeAngleUnits, UnitsTypeEnum.kRadianAngleUnits) 'rad to deg (57.2958)
Dim UserParams As UserParameters = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
Dim MultiList = New ArrayList
MultiList.Clear
If ParameterValue = "True" Then 'convert ParameterValue to boolean
ParameterValue = True
ElseIf ParameterValue = "Null" Then 'convert Null to empty string
ParameterValue = ""
ElseIf IsNumeric(ParameterValue) Then 'convert ParameterValue string to number
ParameterValue = CDblAny(ParameterValue)
If ParameterUnit = "in" Then ParameterValue = ParameterValue * Cnvt_cm_to_in
If ParameterUnit = "deg" Then ParameterValue = ParameterValue * Cnvt_Rad_to_Deg
ElseIf ParameterValue.Contains(",") Then 'process list of values for multivalue
'split each string using comma as the split character
StringArray2 = Split(ParameterValue, ",")
'add strings to arraylist
For Each ListItem In StringArray2 : MultiList.Add(Trim(ListItem)) : Next
'set multivalue param value to the first item in the list
ParameterValue = MultiList.Item(0)
End If
Dim param As Inventor.Parameter
Try'try to get parameter
param = UserParams.Item(ParameterName)
Catch'The parameter doesn't exist so add it
param = UserParams.AddByValue(ParameterName, ParameterValue, ParameterUnit)
'set value and comment for existing params
param.Value = ParameterValue
param.Comment = ParameterComment
'if multivalue then set list
If MultiList.Count > 0 Then MultiValue.List(ParameterName) = MultiList
End Try
oObjectCollection.Add(param)
End Sub
Sub Add_Parameter_Group(ParameterGroupName As String)
Dim oDoc As Document = ThisDoc.Document
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oCustomParamGroup As CustomParameterGroup
Dim ParameterGroup As CustomParameterGroup
Try
'Delete CustomParameterGroups if one exist in order to add new parameters
oCompDef.Parameters.CustomParameterGroups("ID_" & ParameterGroupName).Delete
Catch
End Try
'create group
ParameterGroup = oCompDef.Parameters.CustomParameterGroups.Add(ParameterGroupName, "ID_" & ParameterGroupName)
'add parameters to group
For Each oParam In oObjectCollection
ParameterGroup.Add(oParam)
Next
End Sub
results should look like this
