[python-win32] I need to make a COM object with py2exe. Please HELP!
Tim Roberts
timr at probo.com
Fri May 1 20:09:45 CEST 2015
Diego Vélez Torres wrote:
>
> After studying the "Python Programming on Win32" book, I was able to
> make COM servers . But so far I can pass simple arguments (in both
> directions) between Visual Basic and the Python COM server (e.g.
> integers, strings, floats and arrays). I wonder if it's possible to
> return from the COM server other kind of objects such as graphics to
> be used directly from the .NET program.
>
> To be more precise, I have Python code that uses heavily Numpy and
> Matplotlib. I want to make a COM server that returns images generated
> with Matplotlib in order to use within Excel. The best solution I
> came out was to store the Matplotlib's images as .PNG in temporary
> files. The COM server would return their paths so Visual Basic could
> insert them into the spreadsheet with its own commands.
>
> Though this solution may work, the images cannot be interactive. A
> change would require the creation of new images each time, store them,
> reload them back, etc... all processes together are expensive.
> Therefore, I wish I could return directly from the COM server an image
> object that Visual Basic could handle. Another reason why I want to
> return an image object directly is because I want to use remote COM
> Servers (DCOMs); where the path solution may not work.
You are trying to cross-connect several very different worlds here. You
are going to be in for a lot of frustrating experimentation.
HOWEVER, before we start brainstorming wild ideas, let me point out
something that you may have overlooked. You, right now, are using the
CPython implementation, which runs the interpreter as native code. If
you are going to spend a lot of time interacting with .NET, you may not
be aware that there is a complete .NET implementation of Python called
IronPython. It is a full .NET language, supported in Visual Studio,
running under the same Common Language Runtime as the other .NET
languages. And, it supports both NumPy and SciPy.
Theoretically, it should be possible to create an IronPython assembly
and invoke it directly from Excel. It's possible that would be your
least effort solution.
If there is a reason you can't do that (and do some serious thinking
before you discard it), then you probably have to rely on COM. Your COM
object can return other COM objects, although I don't think there are
any interfaces that will be recognized by Excel as native graphics objects.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list