Anyone have any luck using IronPython 2.7.1 with Inventor 2012?

Anyone have any luck using IronPython 2.7.1 with Inventor 2012?

rschader
Advocate Advocate
599 Views
0 Replies
Message 1 of 1

Anyone have any luck using IronPython 2.7.1 with Inventor 2012?

rschader
Advocate
Advocate

Getting to the point of bashing my brain in on this one. I had previously messed around with Python for Windows extensions with Inventor and managed to convert a few examples to that "platform" a few years ago, Now, I would like to explore this further using IronPython for NET, but have limited success.

 

I am using IronPython with Visual Studio 2010 Shell for a nice IDE, but I am having numerous problems trying to use Inventor's namespaces(?). For example, I had previously converted the AddOccurence example from the programming help file to run under pythonwin with few problems. So far in IronPython, I have the following code:

 

import clr
import System
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReference("Autodesk.Inventor.Interop")
from System.Windows.Forms import *
from System.Runtime.InteropServices import Marshal
Inventor = Marshal.GetActiveObject('Inventor.Application')
from Inventor import DocumentTypeEnum

oDoc=Inventor.ActiveDocument
doctype = Inventor.ActiveDocumentType
if doctype == kPartDocumentObject :
	MessageBox.Show("Active Document Type: Part Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kAssemblyDocumentObject :
	MessageBox.Show("Active Document Type: Assembly Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kDrawingDocumentObject :
	MessageBox.Show("Active Document Type: Drawing Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kPresentationDocumentObject :
	MessageBox.Show("Active Document Type: Presentation Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kDesignElementDocumentObject :
	MessageBox.Show("Active Document Type: Design Element Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kForeignModelDocumentObject :
	MessageBox.Show("Active Document Type: Foriegn Model Document","Add Occurence")
elif doctype == Inventor.DocumentTypeEnum.kSATFileDocumentObject :
	MessageBox.Show("Active Document Type: SAT File Document","Add Occurence")
else:
	MessageBox.Show("Active Document Type: Error","Add Occurence")


Marshall.GetActiveObject('Inventor.Application') works fine to get the running instance of Inventor, with or without the clr.AddReference("Autodesk.Inventor.Interop". The main problem I am having right now is figuring out how to access the values of Inventor.DocumentTypeEnum (like kDrawingDrocumentObject). It will not recognise Inventor.DocumentTypeEnum.kWhatever , DocumentTypeEnum.kWhatever , or just kWhatever, even though the call to ImportDocumentTypeEnum is successful, I get errors that the name is not defined, either for the enum value or the main DocumentTypeEnum? 

Anyone know what I am doing wrong? ActiveDocument and ActiveDocumentType seem to work fine, I just don't like having to reference those cryptic numbers for enum testing, I'd rather use the constants. Thanks in advance to anyone that can help with this!

 

0 Likes
600 Views
0 Replies
Replies (0)