Change Parameter from selected part

Change Parameter from selected part

GeorgK
Advisor Advisor
548 Views
5 Replies
Message 1 of 6

Change Parameter from selected part

GeorgK
Advisor
Advisor

Hello together,

 

this code works for parts. But how to change it that it works for assemblys? I would like to select a part and than change the value.

 

m_invApp = GetObject(, "Inventor.Application")
        ' Get the Parameters object. Assumes a part or assembly document is active.
        Dim oParameters As Parameters
        oParameters = m_invApp.ActiveDocument.ComponentDefinition.Parameters
        ' Get the parameter named "Length".
        Dim oLengthParam As Parameter
        oLengthParam = oParameters.Item("Diam")
        ' Change the equation of the parameter.
        oLengthParam.Expression = TxtBox10.Text
        ' Update the document.
        m_invApp.ActiveDocument.Update()

 

Thanks

 

Georg

0 Likes
549 Views
5 Replies
Replies (5)
Message 2 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Hi Georg,

 

ActiveDocument.ComponentDefinition means the ComponentDefinition of the assembly if the active document is an assembly. So the code will access the params of assembly, instead of the part. So for your case, the code could looks like below. Please pay attention to the code in color.

 

       m_invApp = GetObject(, "Inventor.Application")
        ' Get the Parameters object. Assumes a part or assembly document is active.

 

        ' assume one part is selected.

        Dim oOcc As ComponentOccurrence
        oOcc = m_invApp.ActiveDocument.SelectSet(1)
     

       ' get the part ComponentDefinition
        Dim oPartDef As PartComponentDefinition
       Set oPartDef = oOcc.Definition

 

         ' get the params of the part
           Dim oParameters As Parameters
       ' oParameters = m_invApp.ActiveDocument.ComponentDefinition.Parameters

     oParameters = oPartDef .Parameters


        ' Get the parameter named "Length".
        Dim oLengthParam As Parameter
        oLengthParam = oParameters.Item("Diam")
        ' Change the equation of the parameter.
        oLengthParam.Expression = TxtBox10.Text
        ' Update the document.
        m_invApp.ActiveDocument.Update()

0 Likes
Message 3 of 6

GeorgK
Advisor
Advisor

Thank you very much. Is it possible to keeb the selected part selected?

0 Likes
Message 4 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

if you find the occurrence is not selected, you can use Document.SelectSet.Select to select it again.

0 Likes
Message 5 of 6

GeorgK
Advisor
Advisor

I tried to select the part but it does not work. Please could you post an example.

0 Likes
Message 6 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

It is very straightforward. just input the entity you want to select in the method

 

Document.SelectSet.Select.

 

I am starting to be curious how you did. Could you share your code? 

0 Likes