How can I create these "Parameters" with iLogic instead of using the Parameters window?

How can I create these "Parameters" with iLogic instead of using the Parameters window?

chris
Advisor Advisor
1,551 Views
21 Replies
Message 1 of 22

How can I create these "Parameters" with iLogic instead of using the Parameters window?

chris
Advisor
Advisor

I'm trying to see if there is an easier way to create "User Defined Parameters" instead of using the Parameters window in Inventor. I need to be able to create each parameter with an "initial" value, but then obviously be able to change that value later. The below example shows a numeric in, numeric angle, unitless, text and true/false.

 

I'd like to know if I can also set up the multi-value list when creating these in iLoigc, as well as add the notes, and also if it is a key or to be exported?

 

Is this possible and can someone show an example?

 

I have a project where I have to enter a ton of user defined parameters and I want to group them, and inevitably you always forget a parameter when trying to group them and of course we can't we order in the parameters window... ;-(

 

chris_0-1739418960979.png

 

0 Likes
Accepted solutions (2)
1,552 Views
21 Replies
Replies (21)
Message 21 of 22

Curtis_Waguespack
Consultant
Consultant
Accepted solution

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

Curtis_Waguespack_0-1741194804677.png

 

EESignature

Message 22 of 22

chris
Advisor
Advisor

@Curtis_Waguespack This works great! I was really hoping that when I tried to link a part or assembly that has "Parameter Groups" that they'd show up in the "linked Parameter" list, that way I could easily link a group without having to pick and choose which user defined parameters from what could be a very long list... that's a major bummer 😞

 

chris_1-1741195890370.png

 

0 Likes