Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic New parameter in part

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
johan
1413 Views, 11 Replies

Ilogic New parameter in part

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)

 

 

 

11 REPLIES 11
Message 2 of 12
dkatz
in reply to: johan

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"

Message 3 of 12
Vladimir.Ananyev
in reply to: dkatz

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 12
johan
in reply to: Vladimir.Ananyev

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
 
Message 5 of 12
dkatz
in reply to: johan

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?

Message 6 of 12
johan
in reply to: dkatz

Looks like it works if i use

 

SyntaxEditor Code Snippet

MultiValue.SetListInComponent(oDoc.DisplayName,"ParameterName","Value","Value")
Message 7 of 12
Vladimir.Ananyev
in reply to: johan

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 8 of 12
johan
in reply to: Vladimir.Ananyev

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"
Message 9 of 12
Vladimir.Ananyev
in reply to: johan

You need to update the part document in order to apply parameter changes.
invPart.Update()

Hope it helps.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 10 of 12
johan
in reply to: Vladimir.Ananyev

I forgot to copy that line, and no it dosnt work even when updated
Message 11 of 12
johan
in reply to: johan

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
Message 12 of 12
awatt
in reply to: johan

Did you figure this one out?  I think I'm getting the same thing.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report