Updating part file parameters with Python

Updating part file parameters with Python

20854706
Explorer Explorer
1,207 Views
8 Replies
Message 1 of 9

Updating part file parameters with Python

20854706
Explorer
Explorer

Dear forum users,

 

Is there a way to use Python to update certain parameters within a part file in Inventor? I've searched the forum, and the closest I could come to a solution is a post about adding missing parameters, which is not what I want to do. 

 

Any help would be extremely helpful.

 

Kind regards 

0 Likes
Accepted solutions (1)
1,208 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

this rule will update a parameter

import win32com.client
from win32com.client import gencache, Dispatch, constants, DispatchEx

ThisApplication = win32com.client.Dispatch('Inventor.Application')
ThisApplication.Visible = True
CastTo = gencache.EnsureModule('{D98A091D-3A0F-4C3E-B36E-61F62068D488}', 0, 1, 0)
ThisApplication = CastTo.Application(ThisApplication)

oDoc = ThisApplication.ActiveDocument
oDoc = CastTo.PartDocument(oDoc)

params = oDoc.ComponentDefinition.Parameters

parameter1 = params.Item("MyParameterName")
print("number of Parameters: ",parameter1.Value)

parameter1.Value = 2.0
print("number of Parameters: ",parameter1.Value)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 9

20854706
Explorer
Explorer

@JelteDeJong Thank you for your reply. It works! Although, while the parameter updates, the part does not. Is there a way to force the update rather than manually clicking on the "Update" button on the Manage tab? 

 

My goal is to update the whole part with the new values, then export it as a .stl file after all the updates have happened. 

 

Is it possible to make this all automatic? 

0 Likes
Message 4 of 9

JelteDeJong
Mentor
Mentor

you can try:

oDoc.Update()
oDoc.Update2()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 9

20854706
Explorer
Explorer
@JelteDeJong Thank you again for the quick reply. The first line worked!
The last thing that I'm struggling with is exporting the file after I made the updates to the parameters. Is there a possible way of doing this?
0 Likes
Message 6 of 9

JelteDeJong
Mentor
Mentor

what do you mean by exporting? do you want to create dxf's or pdf's?

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 9

20854706
Explorer
Explorer

@JelteDeJong, I want to export the part as a .stl file type.

0 Likes
Message 8 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

try this:

newFileName = "d:\\temp\\test.stl"
oDoc.SaveAs(newFileName, True)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 9

20854706
Explorer
Explorer
Thank you very much! You've been a great help!
0 Likes