Integrating .Net and Maya UI - Pt1

Hey all,

It’s been a long time coming and now I have gotten it all sorted. I have just written up a post on “Embedding .Net windows properly within Maya”, its the first of two. Tell me what you think, does it needs more detail or supporting posts.

Cheers,

Butters

~B)

This is a great start. I’m looking forward to seeing how you attach native Maya widgets to the window. I’ve always had mixed success on that side.

I noticed that you were able to add a reference to an assembly that had a different name than the internal namespace. Perhaps this was a bug with python.net that has been fixed. I’ll have to see whether this works for me now. This was a big pain in the @#$%.

Oh also, I’ve noticed that python will have issues when loading native python libraries (.pyd) after the clr is imported. If you run into this, you need to change your load order so that they get loaded before you load the clr.

If you’re not using it, take a look at Python Tools For Visual Studio: http://www.ironpython.net/tools/ It is the portion of IronPython that offers the VS integration. Pretty well done. The fact that it understands how python modules work, and can do autocompletion on code that isn’t even part of your current project is pretty amazing. It also has integrated debugging, and while you can use “attach to process” to debug Maya python, it doesn’t seem to be working correctly due to a conflict with Maya’s internal debugger.py hooks into Python. If someone helped them sort this out, this would be a brilliant solution to debugging this stuff. In theory you could debug all the way from Python up into a C# assembly.

Cheers for that Brett,

I’m waiting for the second part too. Best part!
I have a couple of ideas on how I should do it, I need to do a some more tests to make sure it’s all sweet.

I’ve had no issue with the order in which import has been placed so far and the differing name spaces in 2009. Thanks for the heads up tho and will keep that in mind :slight_smile:

A proper integration of Python for Maya in VS would be fantastic, and as you say debugging at all levels. Get it working with Express and we have the perfect free alternative. It’s been half a year or so since I looked at the ironpython site, about time to check it out again.

If you get anything going with that or hear anything, make sure you tell me about it.

~B)

Thank you for the info! I do have a question though. I got Python .net to import fine with regular Python 2.6.4. However, when I go into Maya 2011 it gives me an error of “SystemError: dynamic module not initialized properly” . I tried rebuilding with the Python .net source with Visual Studio 2008, which rebuilt fine, but I still get the error inside of Maya. I rebuild with .net 2.0, which is as far back as it would let me go when I went into the drop down list to change it. I just wanted to see if anyone had any ideas on getting this to work with 2011.

thanks!

May be an issue of 32 v 64 bit?

[QUOTE=mgraessle;9992]Thank you for the info! I do have a question though. I got Python .net to import fine with regular Python 2.6.4. However, when I go into Maya 2011 it gives me an error of “SystemError: dynamic module not initialized properly”

thanks![/QUOTE]

Smae problem here in 2011 or 2012. No matter the bitness just does not work/import into those packages =(

Just some further info as I look at the problem. Seems to be a trust issue.

If I compile the source as a 2.7x32 or a 2.6x64 DLL and load it next to my regular python installs, it works perfect.

If I try to load it from inside the Autodesk folder or across a network share, I get the error reported.

Doing some looking and it seems there are definate issues with CAS and the DLLs and I am not sure how that fits with the Maya stuff per se.

To avoid further confusion I have adjusted the tutorial to be 2009 Specific and I will be creating an addition tutorial for 2011/2012…

@Alexander That is interesting to know, what version of windows are you running and what privileges do you have? I know that we had some major issues with work locking down the computers, to “protect” the user.

~B)

[QUOTE=DrBob;10040]To avoid further confusion I have adjusted the tutorial to be 2009 Specific and I will be creating an addition tutorial for 2011/2012…

@Alexander That is interesting to know, what version of windows are you running and what privileges do you have? I know that we had some major issues with work locking down the computers, to “protect” the user.

~B)[/QUOTE]

Fortunately I am in the realm of “trust”. Since we are in R&D and have the need to mutate over the course of the day/week/etc… we get a little more leeway access and perms wise.

Currently we are on flavor 7. Obviously it is way more stringent, especially poking things into the program folder now, so that may be the issue I am having with it when I stuff the DLLs in there.

Just as a test I did roll off a copy of the DLL for 2009x64 and stuffed it into the Maya\python\libs\etc…

Same problem, so it is probablly not “Maya” specific per se.

Very interesting Indeed! I’ve seen some other tutorial for Maya and .Net, just have to take my time and try to do my own implementation, Thank you!

Hey All, I’ve updated the Maya 2009 Tutorial and added and updated one for 2012.

@Brett: Yes it appears that there is still a fault with the name spacing, I have included that tit bit in the tute, cheers.

@Alexander: Any luck with the import? If it’s still not working I can build you some files for testing?

As a side note I found some interesting info on Qt windows the other day, which I need to explore a little further. The UI seems to be drawing multiple times (4 to be exact), might have to check the Qt forums… I’ll keep you guys posted on that.

~B)

[QUOTE=DrBob;10120]Hey All, I’ve updated the Maya 2009 Tutorial and added and updated one for 2012.

@Alexander: Any luck with the import? If it’s still not working I can build you some files for testing?

~B)[/QUOTE]

I’ll take a look at your 2012 setup. 64? That is from where the problems seem to be coming.

32bit on the cmd line works fine. I unfortunately do not have a Maya 32bit to test against (too lazy to install right now), but I am going to assume it most likely works =)

64bit seems to be the beast.

I fyou want to build some test files, by all means. You can email me at:

[email protected] or
[email protected]

Cheers!

p.s. fresh build of PythonNet 2.6,UCS2 for x64. Inside Maya:

import dotnet
from dotnet import clr

Error: line 1: dynamic module not initialized properly

Traceback (most recent call last):

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

SystemError: dynamic module not initialized properly

import dotnet? just import clr, as long as you have compiled the file correctly and dropped the clr.pyd and Python.Runtime.dll in the Maya bin directory you should be right.

~B)

[QUOTE=DrBob;10127]import dotnet? just import clr, as long as you have compiled the file correctly and dropped the clr.pyd and Python.Runtime.dll in the Maya bin directory you should be right.

~B)[/QUOTE]

That is irrelevent =) It is part of our sitecustomize.py

We have a structure that allows libraries of whatever flavor of python interpreter you fire up (2008/2009 in 2.5.4x64 2012 in 2.6x64 or clients in 2.7.1x32) to load their paths dynamically so everything still works.

The folder we have for the pythonnet stuff is underneath dotnet.

Regardless, as I said, in or out, only works from the cmd line, not in any flavor of Maya x64.

Right, I see! I never liked having to support multi-versions of software, but sometimes you don’t get a choice.

I’ll shoot through the compiled files for you for Maya 2012 x64, see how they go for ya.

~B)

Hey guys,

Just want to throw up some information Robert has been helpful in generating.

He was able to get me a build that actually works! except, it will only work from a local drive because of .net and bounding issues of DLLs running from across network locations.

SO, does anyone have an idea how to resolve the security side of the DLL being able to run from a network drive without having to use CAL to set the permissions on every machine?

Didn’t MS fix this problem in 3.5+ ?

Because I can’t get the DLL to work if I build a 3.5 or a 4.0 version, it is the same behavior, works fine locally, across a network mapping, nada.

Cheers.