Inventor Customization

Inventor Customization

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

Change Parameter from selected part

193 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,305
Registered: ‎06-12-2011
Message 2 of 6 (184 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: 155
Registered: ‎09-21-2006
Message 3 of 6 (177 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,305
Registered: ‎06-12-2011
Message 4 of 6 (161 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: 155
Registered: ‎09-21-2006
Message 5 of 6 (122 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,305
Registered: ‎06-12-2011
Message 6 of 6 (107 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!