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