@chris , ah yeah I had it sorta hardcoded for 1
there is this in the sub, that catches the 1 and converts it from string to double, to prevent a data type mismatch error later
ElseIf ParameterValue = "1" Then 'convert ParameterValue string to number
You can replace that line with this so that it is not just looking for 1, but is looking at the string to see if it is numeric, and then you can set your default inch, angle and and unitless to any number, so it's more flexible.
Note too, I added an example for setting a default text value of nothing, just in case it is of use.
Sub Main
Dim ParamList As New ArrayList
' Name | Value | Unit | Comment
ParamList.Add("User_Parameter_001|7.125|in|")
ParamList.Add("User_Parameter_002|8|deg|Draft Angle")
ParamList.Add("User_Parameter_003|9|ul|Number of Holes")
ParamList.Add("User_Parameter_004|Red, Blue, Green|Text|Type of Holes")
ParamList.Add("User_Parameter_005|True|Boolean|Show Holes")
ParamList.Add("User_Parameter_999|Null|Text|Test 999")
'send striing to sub routine
For Each ParamString In ParamList : CreateParams(ParamString) : Next
iLogicVb.UpdateWhenDone = True
End Sub
Sub CreateParams(ParamString As String)
'split each string using the | as the split character
StringArray = Split(ParamString, "|")
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
End Sub
