This sets a multi value parameter in a part from the assembly --> MultiValue.SetListInComponent(Partname,Parametername, Value, value, value)
But how do i create a new parameter if it dosnt exist in the part? (from the assembly)
Solved! Go to Solution.
Solved by johan. Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
http://modthemachine.typepad.com/my_weblog/2013/08/updating-parts-through-an-assembly.html
This should get you going. I searched for "add parameter in inventor ilogic"
The following rule creates the numeric user parameter and makes it multi-value:
'reference to the document object Dim oDoc As PartDocument = ThisDoc.Document 'reference to the user parameters collection Dim oPars As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters 'data for the multi-value list Dim List() As String = {"11","88","77","66"} 'create parameter, current value is the first in the list Dim oPar As UserParameter = oPars.AddByExpression("Width", List(0), "mm") 'set the multi-value list in the parameter oPar MultiValue.List("Width") = List oDoc.Update ' apply parameters
cheers,
This is as close as i get, and this generates this error
" MultiValue: Could not find a parameter named: "ParameterName" "
SyntaxEditor Code Snippet
Sub main
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim doc As Document For Each doc In asmDoc.AllReferencedDocuments If doc.DocumentType = kPartDocumentObject Then MakeParam(doc) End If Next End Sub
SyntaxEditor Code Snippet
Function MakeParam(strPartname) Dim oDoc As Document oDoc = strPartname MsgBox(strPartname.fullfilename) Dim oPars As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim List() As String = {"11","88","77","66"} Dim oPar As UserParameter = oPars.AddByExpression("ParameterName", List(0), "mm") MultiValue.List("ParameterName") = List oDoc.Update End Function
I think the problem is the MultiValueList command is trying to happen at the Assembly level, not at the part level.
MultiValue.List("ParameterName") = List
So, I tried this
MultiValue.List(oDoc.DisplayName,"ParameterName") = List
It kind of worked, but I'm not sure it's right (I'm trying to get to how you call a parameter of a part through an assembly, like this:
Parameter("Part1:1", "d0") = 1.2
I am just not sure if displayname is the right thing to use here.
Vladimir, can you weigh in on that?
Looks like it works if i use
SyntaxEditor Code Snippet
MultiValue.SetListInComponent(oDoc.DisplayName,"ParameterName","Value","Value")
MultiValue.SetListInComponent function works fine with components’ names.
But I get error if try to use this function with the Inventor.Document argument.
The following VB-version of iLogic rule works with documents. It adds the multi-value
parameter “AAA” to all referenced part documents ignoring the assembly hierarchy.
Sub Main 'active assembly Dim asmDoc As AssemblyDocument = ThisDoc.Document 'ThisApplication.ActiveDocument 'iterate the referenced documents For Each doc As Inventor.Document In asmDoc.AllReferencedDocuments 'add the multi-value parameter to every part document If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then AddMultiValueParameter(doc) End If Next asmDoc.update Beep End Sub Sub AddMultiValueParameter(ByVal oDoc As PartDocument) Dim ParName As String = "AAA" 'Parameter Name Dim oList() As String = {"11", "88", "77", "66"} Dim oPars As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oPar As UserParameter = Nothing Try oPar = oPars.Item(ParName) oPar.Delete() Catch ex As Exception End Try 'create parameter with the first value from the list oPar = oPars.AddByExpression(ParName, oList(0), "mm") 'add expression list For i As Integer = 0 To oList.Length - 1 oList(i) = "" & oList(i) & "" '<-- required Next Dim oExprList As ExpressionList = oPar.ExpressionList Call oExprList.SetExpressionList(oList, False) oDoc.Update() End Sub
cheers,
Thank you!!
I have stumbled on another little problem when adding a value in the multi value parameter.
This creates the parameter value in the part but when i rightclick on the Parameter (Manage/Parameters) row and select
edit multi-value list the value dosnt show.
And i am trying to set multiple values from a dynamic array but i dont get it to work.
Any ideas?
SyntaxEditor Code Snippet
Dim invPart As Inventor.PartDocument Dim oCompOcc As Inventor.ComponentOccurrence oCompOcc = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName("PartName") invPart = oCompOcc.Definition.Document InvParam = invPart.ComponentDefinition.Parameters.Item("ParameterName") InvParam.Value = "TestValue"
You need to update the part document in order to apply parameter changes.
invPart.Update()
Hope it helps.
This is how to set a dynamic array to multi value parameter, if anyone ever need it.
SyntaxEditor Code Snippet
For i = 0 to 5
redim preserve strArr(i)
strArr(i) = "What ever "& i
next
setParamValues(oOccurrence.Name, "ParameterName", strArr) Public Function setParamValues(strPartName As String, strParaName As String, strValues() As String) MultiValue.SetListInComponent(strPartName,strParaName, strValues) End Function