I am trying to extract the parameters of an Inventor part (.ipt) with Python, using the following code:
#Open Inventor
invApp = win32com.client.Dispatch("Inventor.Application")
#Make inventor visible
invApp.Visible = True
#Set file names of template
Part_FileName_BaseIPT = 'C:\\Base.ipt'
#Open the base model
oPartDoc=invApp.Documents.Open(Part_FileName_BaseIPT)
#Collect parameters
oParams = oPartDoc.ComponentDefinition.Parameters
(It is part of a code snippet I found here: Using python to automate Autodesk Inventor)
I get the following error message: …' object has no attribute 'ComponentDefinition'
Any ideas what´s wrong?
Could it be that I have to tell Python somehow that oPartDoc is related to a Part Document (and not to an Assembly Document). In VBA retrieving the paramters of a part would look like this:
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
Dim param As Parameter
Set param = partDoc.ComponentDefinition.Parameters
I suppose that the information given in the first line of VBA is missing so far in the Python code.
This is part of the Inventor API Object model table, which might be helpful for the solution: API Object model
Unfortunately the use of the Inventor API with Python is documented very poorly, also a post in the Autodesk forum did not bring any solution. But since Python is the only programming language I know, I have to rely on it.
I have been trying to solve this for quite a while now, any help would be highly appreciated!
(I use Inventor 2018, Python 3.6.2 (Anaconda) and Windows 10.)