[IronPython] Problem with com object

Dave Fugate dfugate at microsoft.com
Wed Feb 10 17:48:04 CET 2010

Offhand, the Python snippet you've sent appears fine.  When you run this against IronPython, can you pass the "-X:ExceptionDetail" flag to ipy.exe and send back the results?

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Alberto Fernandez
Sent: Wednesday, February 10, 2010 2:59 AM
To: users at lists.ironpython.com
Subject: [IronPython] Problem with com object

Hello all,

Please excuse me if what I'm asking is trivial but I'm just starting with anything .net related and ironpython. I have a little experience programing c++ and python but I'm not a professional programmer.
What I'm trying to do is write a macro for a program through its com connectivity. The reason is that I do not know much (and I don't like what I know) about VBA. I also would like to reuse code that I've written in pyhton.
The problem that I have is that I get an error message "HRESULT E_FAIL" when I try to do anything with the generated object. However, I can see that the application launches. In fact, what I think is the equivalent code in VB seems to work.
VB code:
Module Program
	Sub Main()
		Dim catia As INFITF.Application
		catia = CreateObject("CATIA.Application")
		'catia = System.Runtime.InteropServices.Marshal.getActiveObject("CATIA.Application")
		Console.Write("  Press any key to continue . . . ")
	End Sub
End Module

The code that I'm using in ironpython is:

import System
import INFITF
t = System.Type.GetTypeFromProgID("CATIA.Application")
CATIA = System.Activator.CreateInstance(t)
print CATIA.caption
print "final"

I can see the application starting too but as soon as I try to probe it or do something I get the error.
I'm sure missing something but I do not know what.
By the way I'm using sharpDevelop as IDE. It is one of the reason I would like to go this route, it facilitates me a lot any GUI that I may want to include.
I've been fighting with this for two days. I can connect and work using win32com in regular python but I'm not able to go that route with ironpython either.
thank you a lot for your time.

Alberto Fernandez
Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list