Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
marcin_bargiel
in reply to: b.vonklass

Sub Main
	Add_Parameters
End Sub

Sub Add_Parameters
Dim doc As PartDocument
doc = ThisDoc.Document

Dim pcd As PartComponentDefinition
pcd = doc.ComponentDefinition

If ThisApplication.ActiveDocumentType = kPartDocumentObject Then
	
MultiValue.UpdateAfterChange = True
MultiValue.SetValueOptions(True)

'example to only setmulivalue
j = 10
For i = 1 To j : Try : If Parameter("k_flange_N" & i) <> -100 Then : End If : Catch : doc.ComponentDefinition.Parameters.UserParameters.AddByExpression("k_flange_N" & i, 1, "mm")  : End Try : Next
For i = 1 To j : MultiValue.SetList("k_flange_N" & i, -1, 0, 1) : Next


'example to setmulivalue and allow custom value
j = 20
index_no = 2
For i = 1 To j : Try : If Parameter("set_N" & i) <> -100 Then : End If : Catch : doc.ComponentDefinition.Parameters.UserParameters.AddByExpression("set_N" & i, 0, "mm")  : End Try : Next

For i = 1 To j 
	MultiValue.SetList("set_N" & i, -2, -1, 0, 1) 
	Set_Attributes_To_Mulitivalue("set_N" & i)
	'set default index value
	Dim oParam1 As UserParameter  
	oParam1 = ThisDoc.Document.componentdefinition.parameters.item("set_N" & i)
	oParam1.ExpressionList.SetExpressionList(oParam1.ExpressionList.GetExpressionList(), True, index_no)
Next

RuleParametersOutput()							
InventorVb.DocumentUpdate()

End If
End Sub


Function Set_Attributes_To_Mulitivalue(PARAM_NAME As String)
Dim doc As PartDocument
doc = ThisDoc.Document

Dim pcd As PartComponentDefinition
pcd = doc.ComponentDefinition
	
	Try
        Dim paramAttribSet As AttributeSet
		pcd.Parameters.UserParameters.Item(PARAM_NAME).AttributeSets.Add("com.autodesk.inventor.ParameterAttributes")
        paramAttribSet = pcd.Parameters.UserParameters.Item(PARAM_NAME).AttributeSets.Item("com.autodesk.inventor.ParameterAttributes")

        Try
            paramAttribSet.Add("AllowCustomValue", ValueTypeEnum.kIntegerType, 0)
        Catch ex As Exception

        End Try

        paramAttribSet.Item("AllowCustomValue").Value = 1
	Catch
		
	End Try
End Function
Vote for REPLACE VARIES !
REPLACE VARIES