- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm having difficulty importing an assembly file into python. There seems to be a conflict between the output when I check Document.Type and Document.DocumentType. The second recognises that the file is an an assembly. But the first returns the ‘Document’ ObjectType which needs to also be an assembly one so that I can manipulate it properly.
Does anyone know how I can force the object type to change?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Are you using python for Inventor or fusion?
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Currently inventor, but it does look like restarting with fusion might save a lot of hassle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was not aware that it was possible to automate Inventory with python. Usually you would vb.net or C# (or C++). just out of curiosity how did you manage to get the inventor objects in python?
The .Type is a general property that you will find on almost all Inventor object.
The .DocumentType is more specific.
And if you need to fine more specific information you should look at the Document.SubType. For example if you want to know if you have a sheetmetal part.
https://adndevblog.typepad.com/manufacturing/2013/01/inventor-document-sub-types.html
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It works to some extent. I think the issue must be that you cannot define the variable type before setting its type.
Here is the code I have:
import win32com.client
from win32com.client import gencache, Dispatch, constants, DispatchEx, GetActiveObject
# tries to open inventor or creates a new instance
try:
invApp = GetActiveObject('Inventor.Application')
except:
invApp = Dispatch('Inventor.Application')
invApp.Visible = True
# No idea what this does but was recommended by the guy who wrote it originally
mod = gencache.EnsureModule('{D98A091D-3A0F-4C3E-B36E-61F62068D488}', 0, 1, 0)
invApp = mod.Application(invApp)
# Defines the active doc as a variable
oPartDoc = invApp.ActiveDocument
print(oPartDoc.Type)
print(oPartDoc.DocumentType)
Both the type and document type return different values. Being:
oPartDoc.Type - 50332160 which is the ObjectTypeEnum for Document
oPartDoc.DocumentType - 12291 which measn Assembly Document
oParts = oPartDoc.ComponentDefinition.BOM
When I try to return the BOM I get an error stating:
'<win32com.gen_py.Autodesk Inventor Object Library.Document instance at 0x2791884160736>' object has no attribute 'ComponentDefinition'
I hope this clarifies where the issue comes from. I hope I'm just doing something simple wrong.
Many thanks,
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
the property "invApp.ActiveDocument" will always return a object of the type "Document". the "Document" type does not have a property "ComponentDefinition". The type "PartDocument" has this property. Therefore you need to tell the compilere that it is save to treat the "invApp.ActiveDocument"as a "PartDocument". In VB.net you would do it like this:
Dim oPartDoc As PartDocument = invApp.ActiveDocument
or in C# (which is a bit more strict)
PartDocument oPartDoc = (PartDocument)invApp.ActiveDocument
But I dont know how you would cast in Python.
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You hero, I found the casting thing.
For reference that is what the mod thing is for:
oAssemblyPartDoc = mod.AssemblyDocument(oPartDoc)
This turns the regular document:
Autodesk Inventor Object Library.Document instance
Into an assembly document:
Autodesk Inventor Object Library.AssemblyDocument instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The variable 'mod' contains reference to "Autodesk Inventor Object Library" which describes the Inventor API objects.
In my opinion you can rename this variable to something like "inventorApi".
see registry for more info
HKEY_CLASSES_ROOT\TypeLib\{D98A091D-3A0F-4C3E-B36E-61F62068D488}\1.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
After some googling I found this
It looks like a nice example
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.
Blog: hjalte.nl - github.com