How to create multi-values ​​in subdocuments by opening an assembly and running the rule

How to create multi-values ​​in subdocuments by opening an assembly and running the rule

HYOSEOK-KIM
Participant Participant
256 Views
3 Replies
Message 1 of 4

How to create multi-values ​​in subdocuments by opening an assembly and running the rule

HYOSEOK-KIM
Participant
Participant

I want to open an assembly and configure ilogic to create multi-valued parameters in sub-assemblies or assemblies.

 

inventor version : 2025

 

here my code

-----------------------------------

Imports Inventor.UnitsTypeEnum
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
'Dim oPartCompDef As PartComponentDefinition = docFile.ComponentDefinition
'Dim oUParameter As UserParameters = oNewParameter.UserParameters
'Dim oParam As Parameter
'oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
 
Dim docFName As String
docFName = docFile.FullFileName
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
 
Dim SURFACE_TREATMENT As New List(Of String)
SURFACE_TREATMENT.Add("111")
SURFACE_TREATMENT.Add("222")
 
Dim HEAT_TREATMENT As New List(Of String)
HEAT_TREATMENT.Add("a")
HEAT_TREATMENT.Add("b")
HEAT_TREATMENT.Add("c")
HEAT_TREATMENT.Add("d")
 
docFile.AddByValue(docFName,"SURFACE_TREATMENT", "", UnitsTypeEnum.kTextUnits)
docFile.AddByValue(docFName,"HEAT_TREATMENT", "", UnitsTypeEnum.kTextUnits)
 
Next
----------------------------------
When I run this rule, I get an error.
Is there any way to execute a multi-valued parameter on all subfiles?
0 Likes
Accepted solutions (3)
257 Views
3 Replies
Replies (3)
Message 2 of 4

Stakin
Collaborator
Collaborator
Accepted solution
Imports Inventor.UnitsTypeEnum
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
'Dim oPartCompDef As PartComponentDefinition = docFile.ComponentDefinition
'Dim oUParameter As UserParameters = oNewParameter.UserParameters
'Dim oParam As Parameter
'oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
'Dim FNamePos As Long
'FNamePos = InStrRev(docFile.FullFileName, "\", -1)

'Dim docFName As String
'docFName = docFile.FullFileName
'docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)

Dim SURFACE_TREATMENT As New List(Of String)
SURFACE_TREATMENT.Add("111")
SURFACE_TREATMENT.Add("222")

Dim HEAT_TREATMENT As New List(Of String)
HEAT_TREATMENT.Add("a")
HEAT_TREATMENT.Add("b")
HEAT_TREATMENT.Add("c")
HEAT_TREATMENT.Add("d")





Dim userParams As UserParameters
    userParams = docFile.ComponentDefinition.Parameters.UserParameters
    

    Dim param As Inventor.Parameter

    param =userParams.AddByValue("SURFACE_TREATMENT", "", UnitsTypeEnum.kTextUnits)
param.ExpressionList.SetExpressionList(SURFACE_TREATMENT.ToArray, True, 1)
param =userParams.AddByValue("HEAT_TREATMENT","", UnitsTypeEnum.kTextUnits)
param.ExpressionList.SetExpressionList(HEAT_TREATMENT.ToArray, True, 1)


Next
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

A word of advice about using the ExpressionList.SetExpressionList method...

When the parameter's units are text type, then you will need an extra set of quotation marks around each item in the array of Strings.  When we use the uniquely iLogic 'MultiValue' RuleObject, and one of its methods to set the list, it takes care of that for us automatically.  There is also another very similar uniquely iLogic tool for this type of thing 'iLogicVb.Automation.ParamMultiValues(doc As Document, paramName As String) = String() ', that does it for us automatically also.  So, when using the purely Inventor API way, the 2 primary ways to deal with it are to use Chr(34) (quotation mark character) to add the extra character before & after each entry as you put them into the List/Array ; Or iterate through the List/Array using something like 'For i = 0 To Count - 1' type loop, setting 'List.Item(i) = Chr(34) & List.Item(i) & Chr(34)'...for each of them, just before setting them as the value.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

ryan.rittenhouse
Advocate
Advocate
Accepted solution

I run into the quote often enough that I wrote code to deal with it. If you want to use it, just paste the code below outside of your Sub Main and you can call it like this:

param = userParams.AddByValue("SURFACE_TREATMENT", "", UnitsTypeEnum.kTextUnits)
SetParameterValueList(param, HEAT_TREATMENT)

 

The Sub below will make sure you've got the extra quotes in your values and add them if they are missing.

 

''' <summary>
''' Sets the value list for a given parameter and optionally selects a specific value.
''' </summary>
''' <param name="param">The parameter for which the value list is being set.</param>
''' <param name="valueList">An enumerable collection of string values to populate the parameter's value list.</param>
''' <param name="selectedValue">
''' (Optional) The value to be selected from the value list. 
''' If not provided or not found in the list, the first value will be pre-selected.
''' </param>
''' <remarks>
''' This method ensures that all values in the value list are properly quoted. 
''' If the selected value is provided and exists in the list, it will be pre-selected.
''' </remarks>
Sub SetParameterValueList(param As Inventor.Parameter, valueList As IEnumerable(Of String), Optional selectedValue As String = Nothing)

	Dim paramList As New List(Of String)
	For Each value As String In valueList
		If value.StartsWith("""") Then
			paramList.Add(value)
		Else
			paramList.Add("""" & value & """")
		End If
	Next value
	
	Dim selectedIndex As Integer = 1
	If Not selectedValue Is Nothing Then
		If Not selectedValue.StartsWith("""") Then selectedValue = """" & selectedValue & """"
		selectedIndex = paramList.IndexOf(selectedValue)
	End If
	
	If selectedIndex < 0 Then selectedIndex = 1
	param.ExpressionList.SetExpressionList(paramList.ToArray, True, selectedIndex)

End Sub 'SetParameterValueList

 

If this solved your problem, or answered your question, please click Accept Solution.