Possible to use Python .NET or simmilar inside Maya 2009/10?

Hey guys!

Just discovered the forum here, great stuff.

So I’m trying to bring our c# and maya tools closer together, and it would be great if we could access the same libraries (compiled .dlls) inside of Maya’s python interpreter as I can from tools outside of Maya.

I’ve seen a lot of posts that skirt around this issue, and it seems like people are using Python .NET inside of maya, but i’m unclear how to get this going.

I was looking at this thread:

http://tech-artists.org/forum/showthread.php?t=399&highlight=python+net

and if I build python .NET and move the clr.pyd and the Python.Runtime.dll to the site-packages directory of maya, running:

import clr

in maya produces:

ImportError: No module named clr #

which I suppose isn’t surprising, but if I put these files into a script_path and import it, I get an unhandled exception (GetCLRFunction() is on the top of the callstack) and of course maya crashes.

Has anyone successfully been able to use .NET dll’s inside of maya? Any guidance?

Much Appreciated!

Neil

This has been a really hot topic as of late. DjTomServo is the authority on it, I’m sure he’d be able to help (and he will see this thread I’m also sure). It probably warrants a full featured tutorial, preferably by someone he’s helped get set up :slight_smile:

The quick dirty way to get it up and running is to append the location to your sys.path in your userSetup.py or in your script. For some reason it doesn’t like it if the location lives on PYTHONPATH. Also make sure your build is correct, i’m not sure what version the binaries are built for, but it’s not hard to build it for whatever version of Maya you’re using. The current trunk supports up to 2.6 and x64.

Hey Tom! Nice to meet you.

I’ll try giving that a go, although i’m a little bit confused. By sys.path do you mean the sys path of Python.NET?

Has anybody compiled an article on how to get this going? Or is there another thread that describes this? If not, i’ll write/post an article once we’ve got it going – so that you spend less time helping idiots like me. :slight_smile:

[QUOTE=nschatterjee;4561]Hey Tom! Nice to meet you.

I’ll try giving that a go, although i’m a little bit confused. By sys.path do you mean the sys path of Python.NET?

Has anybody compiled an article on how to get this going? Or is there another thread that describes this? If not, i’ll write/post an article once we’ve got it going – so that you spend less time helping idiots like me. :)[/QUOTE]

SO in your userSetup.py or if you want you could do it in all your scripts, but usually just having it in your userSetup.py is sufficient you could do something like:


import sys
sys.path.append(<path to clr.pyd and Python.RunTime.dll>)

# optional
import clr
clr.AddReference( <frequently used managed assembly> )
import <frequently used managed assembly>

I would skip the optional stuff and do that in your actual script vs doing it in your userSetup.py, but really it doesn’t matter. I haven’t put together much of a doc on it, but honestly that’s really all there is to it, pointing your sys.path to the location of the binaries and importing clr.

Coolio. I’ll do it today and get back to you. Thanks a million man!

PS - our avatars indicate that we should hate each other. :wink:

[QUOTE=nschatterjee;4572]Coolio. I’ll do it today and get back to you. Thanks a million man!

PS - our avatars indicate that we should hate each other. ;)[/QUOTE]

Haha well ok, if that code i posted doesn’t get you any further, then we fight:D:

Well, Tom, Get your plasma rifle ready! :D:

Actually, I did get SOMEWHERE… but alas I’m not up and running. I think I’m building it wrong. :tear:

So I’ve added the path to the the three files to sys.path in the userPrefs.py file:

-clr.pyd
-Python.Runtime.dll
-Python.Test.dll (i’ve also tested without this file in all combinations)

like this:

sys.path.append(“<path to file…>”);

I’ve tried building it in a number of different forms.

No matter how I build it, it doesn’t seem to work.

-I tried the files that came with the pythonnet zip file (even though I knew from what you’ve written elsewhere that it wouldn’t work) and I get this message when I try to “import clr”:

Error: dynamic module does not define init function (initclr)

Traceback (most recent call last):

File “<maya console>”, line 1, in <module>

ImportError: dynamic module does not define init function (initclr)

  • I’ve also tried building (from the Visual Studio solution) in all permutations of the following:

PYTHON25
PYTHON26
(According to the docs, maya 2009 uses Python 2.5.1, so PYTHON25 should be right…)

UCS2
UCS4

and with different Platform Targets:
-“Any CPU”
-“x86”
-“x64”

Result: Nada. In all cases, running “import CLR” results in a maya crash, again with “GetCLRFunction()” on the top of the callstack.

I am trying to build the “pythonnet-2.0-alpha2” version of python.NET. This is marked as “alpha” – is this a bad idea?

I found your post on CG Society ( http://forums.cgsociety.org/archive/index.php/t-524687.html ) and I followed your link to Feihong Hsu’s instructions on building Python .NET ( Feihong Hsu: Installing Python.NET 2.0 Alpha 2 on Windows XP ) We are using Visual Studio 2005 (For reasons which are beyond my control) so I cant’ specify Framework Target through the Project Properties. (Hsu says to set the TARGET FRAMEWORK to .NET 2.0)

I’m downloading Visual Studio Express Edition 2008 to see if I can make it work through that. I’ll post the results ASAP.

In the mean time, can you see what i’m doing wrong?

(BTW- we’re running Maya2009 and i’m using a 32 bit machine, windows XP)

Cheers,
Neil

Sad news! (although more clues)

Building through Visual Studio 2008 (ensuring that we’re building for .NET Framework 2.0…) the .dll still crashes Maya.

I attempted to take the library and put it alongside my standalone python install (which is also 2.5.1) and it worked, no problem. I was able to use my c# libraries there, which was great.

So now the only issue is getting it to work in Maya. Any thoughts as to what I might be missing or what I might try?

Cheers,
Neil