IronPython in Maya

Hi all,

Anyone knows if it’s possible to write Maya plugins 100% in IronPython like Python?

Thanks a lot,
Light

Are you trying to take advantage of IronPython’s Visual Studio integration or are you actually trying to get .NET into Maya?

Hey Seth,

I am trying to get .NET into Maya. But VS integration would be nice too in addition. (:

Thanks,
Light

If you’re trying to get .NET into Maya, I would recommend Python .NET. This is the core of all our .NET/Maya interaction and we’ve had pretty good success with it.

Thanks man, it looks promising. I will check out what it can do.

Ultimately I want to write C# plugins for Maya. That’s why I am trying to get .NET into Maya.

Cheers,
Light

We went down the C# in Maya route a little while ago and had mixed results. I know some folks have done promising work with it, Secret Level and the now defunct Digital Anvil. In fact the stuff we were doing was based off of Digital Anvil’s work. If you’d like, PM me and i can give you the contact info for some of the guys that worked on it, a few of them are kicking around Microsoft’s XNA group and some of them stayed in austin at NCSoft.

As far as C# plugins, i’ve found it’s just as easy to write Maya plugins in Python. The really cool part is that since API calls are now exposed to the scripting level via the Python API, you can actually “sketch out” your API blocks in the script editor, then once you know they work you can incorporate that into a full-on python plugin.

I think i’ve mentioned that one of my pet projects right now is porting all the Complete Maya Programming plug-ins to Python, i really should get off my ass and finish that. If only work would stop getting in the way. . .:D:

Thanks Seth.

Light

Hey… that’s really cool - I didn’t think one could write plug-ins for maya with python. I found a cryptic reference to it online but nothing I could really understand - it was an example of writing a plug-in using python but for a mel command…not sure why anyone would do such a thing.

Do you guys have any simple examples on how to write a plug-in with python?

Denis.

[QUOTE=dekorkh;1252]
Do you guys have any simple examples on how to write a plug-in with python?
[/QUOTE]

I do, just not on my work computer. PM me just so i remember and i’ll post some samples when i get home from work tonight. Also, you can check out:

\Program Files\Autodesk\Maya2008\devkit\plug-ins\scripted

Or whatever directory you have maya installed under, all the devkits 8.5 and later include some scripted plug-in samples.

Hey guys,

I’ve just recently started integrating Python.net into Maya with some success. I have no issues loading and calling functions, but I am a little stuck on callbacks.

With a simple test it crashes Maya 2008. The Dll is a simple form with a button on it.

import maya.cmds as cmds
import clr
from System.Reflection import Assembly
import sys 

Assembly.LoadFile("C:\\Program Files\\Autodesk\\Maya2008\\bin\\DotNetTest.dll")

global dotNetWindow

dotNetWindow = clr.DotNetTest.Form1()
dotNetWindow.Show()

def myCallback(sender, args):
    print 'Button: ', sender.Text

dotNetWindow.button1.Click = myCallback

Any Ideas?

Should I be creating all the UI items in Python?

Cheers,

Rob.

Hi there, guys.

I’m curious to know one thing. I’ve managed to run PythonNet 1.0 under Maya 8.5, however, it only adds support for dotNET 1.1, so, obviously, what I’m after is to get the latest (even though Alpha) version fo PythonNet 2.0 under Maya.

The problem is, when I try to load up the clr.pyd and Python.Runtime.dll in Maya and then try to “import clr” module, it throws an arror saying that the module clr doesn’t define a init function.

Does anyone know of a solution? Thanks a lot in advance, cheers…

If I may ask, how did you manage to run clr under Maya? I’m having trouble getting it run under regular Python.

I complied the Python.Runtime.dll and dropped it in with the clr.pyd file into the “\Maya2008\bin” dir.

[QUOTE=DrBob;1277]I complied the Python.Runtime.dll and dropped it in with the clr.pyd file into the “\Maya2008\bin” dir.[/QUOTE]

Yep, that’s what it needed done in order to make it load in Maya. Thanks for the reply, now I’m onto some dotNET 2.0 testing :slight_smile:

Hmmm… another question.

I’m having problems with threading in Maya. I run my beautiful form from within Maya’s Python interpreter, the form pops up, but Maya looses responsiveness. When I select something etc… the UI in Maya doesn’t get redrawn etc… And basically the form exists “outside” of Maya which makes it really hard to make some nice GUI for tools that need to be on sight while working in Maya.

So, basically, is there a way to get the .NET objects run inside of Maya’s window and still keep the responsiveness?

I tried threading in Python as well as LoopCallbacks in .NET, but nothing seems to be working. Any ideas?

look up the pyQT docs under the devkit folder of your maya installation, it’s under other.

there’s a python module called pumpThread that autodesk provides that makes it so threading is handled by maya and the UI doesnt lock up.

hope that helps,

Luiz

[QUOTE=lkruel;1289]look up the pyQT docs under the devkit folder of your maya installation, it’s under other.

there’s a python module called pumpThread that autodesk provides that makes it so threading is handled by maya and the UI doesnt lock up.

hope that helps,

Luiz[/QUOTE]

Thanks for the tip!

I just had a look at the code, but since it’s aimed at PyQt, it’s kinda hard to adopt for dotNET. There’s a specific property of the PyQt4, called QtGui which has a property called QApplication where they pass in maya.exe as the app.

How can I adopt this through PythonNet?

Here’s an example of how to do forms in Maya with Python .NET from the good folks at Autodesk. This isn’t officially supported, but it should give you a good idea of how to make this work. rename the attachment to .py and you should be good to go. It’s not to dissimilar from what goes on with Qt, you just have to make sure you thread-protect all the forms related stuff. On a side note, while it’s a little difficult for Autodesk to get whole hog into .NET, the folks i’ve talked to about the Python .NET stuff seem pretty enthusiastic about it. I think if more people start using this stuff and actually start showing Autodesk what they’re doing with it (NDAs withstanding and all that), they may feel a bit more incentive to get behind this stuff. Charge!!!

[QUOTE=djTomServo;1293]Here’s an example of how to do forms in Maya with Python .NET from the good folks at Autodesk. This isn’t officially supported, but it should give you a good idea of how to make this work. rename the attachment to .py and you should be good to go. It’s not to dissimilar from what goes on with Qt, you just have to make sure you thread-protect all the forms related stuff. On a side note, while it’s a little difficult for Autodesk to get whole hog into .NET, the folks i’ve talked to about the Python .NET stuff seem pretty enthusiastic about it. I think if more people start using this stuff and actually start showing Autodesk what they’re doing with it (NDAs withstanding and all that), they may feel a bit more incentive to get behind this stuff. Charge!!![/QUOTE]

Hey, thanks a lot! The script works perfectly! It’s a bit heavier to my tastes, so I have to wrap my head around it in order to actually make it work in my own scripts :smiley: but the results are there!

Btw: the last step will be to keep the window active inside Maya when navigating in Maya. So far, the Forms are separate from Maya, which is fine for some kind of tools, but for those you might want to have floating around all the time, it’s not acceptable. I’ll try to look onto that next, as soon as I figure this one out :wink:

Thanks agian, I appretiate it!

Perfect! It was super simple to implement actually! The file you provided, Seth, is a bit too much for what I needed, so I only used the threading functionality and changed just a few lines and it works perfectly.

It’s funny, though, that I’ve been trying to do the same thing (threading) this morning, but with no success. I don’t know what I’d been doing wrong. But anyways, it works now so I’ll try to look for the solution of making the windows “stuck” with Maya :slight_smile: