Inventor Customization

Reply
Distinguished Contributor
GeorgK
Posts: 132
Registered: ‎09-21-2006
Message 1 of 6 (189 Views)

Change Parameter from selected part

189 Views, 5 Replies
07-26-2012 07:53 AM

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

ADN Support Specialist
xiaodong.liang
Posts: 1,263
Registered: ‎06-12-2011
Message 2 of 6 (180 Views)

Re: Change Parameter from selected part

07-31-2012 03:01 AM 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()



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Distinguished Contributor
GeorgK
Posts: 132
Registered: ‎09-21-2006
Message 3 of 6 (173 Views)

Betreff: Change Parameter from selected part

07-31-2012 11:46 PM in reply to: GeorgK

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

ADN Support Specialist
xiaodong.liang
Posts: 1,263
Registered: ‎06-12-2011
Message 4 of 6 (157 Views)

Betreff: Change Parameter from selected part

08-02-2012 01:21 AM in reply to: GeorgK

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Distinguished Contributor
GeorgK
Posts: 132
Registered: ‎09-21-2006
Message 5 of 6 (118 Views)

Betreff: Change Parameter from selected part

12-06-2012 04:19 AM in reply to: xiaodong.liang

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

ADN Support Specialist
xiaodong.liang
Posts: 1,263
Registered: ‎06-12-2011
Message 6 of 6 (103 Views)

Betreff: Change Parameter from selected part

12-18-2012 12:52 AM 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? 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube