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: 

Change Parameter from selected part

5 REPLIES 5
Reply
Message 1 of 6
GeorgK
381 Views, 5 Replies

Change Parameter from selected part

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

5 REPLIES 5
Message 2 of 6
xiaodong_liang
in reply to: GeorgK

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()

Message 3 of 6
GeorgK
in reply to: GeorgK

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

Message 4 of 6
xiaodong_liang
in reply to: GeorgK

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

Message 5 of 6
GeorgK
in reply to: xiaodong_liang

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

Message 6 of 6
xiaodong_liang
in reply to: GeorgK

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? 

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

Post to forums  

Autodesk Design & Make Report