Hey, I’m often running some export-scripts in Maya, and whenever I do that I have to wait for the script to finish before I can interact with Maya. I was wondering if there was some way to kind of say that Maya should run the script at 50%, so that I can still work in Maya as the script runs? I’m using Python btw
Sometimes the easy way is the best way, why not open a new instance of Maya and have the export scripts running on that instance while you work on the “main” Maya instance? Some other way would be having different threads but from what I’ve learned, 1. it’s not a good thing to do in Python and 2. it’s not a good thing to do in Python + Maya
take a look at maya.standalone
The concept of allowing artists to continue working even while a tool is processing has been a guiding principal behind much of my Maya tool development. I’ve not had a ton of luck with multithreading in Maya. (As far as I’m aware it’s impossible to execute any maya.cmds commands from another thread.) You’ll quickly find yourself crashing Maya and getting all sorts of horrible print outs in the console log. The trick to running processes invisibly and “asynchronously” lies in the ability to generate background child processes of Maya. Definitely familiarize yourself with the subprocess Python module. There’s a great introduction with example at this blog. http://www.toadstorm.com/blog/?tag=subprocess
I’ve been meaning to get around to writing up a blog entry on my general framework for managing Maya background processes, but until then, try experimenting with it on your own! I’ve found the amount of processing that can be completed, all from within the confines of a nice Maya tool and without preventing your artists to continue work, is limitless when you take advantage of child processes. Think about the possibilities of executing any programmed executable (any tools your programming team could write) all from within Maya!
You can issue maya commands from another thread, but you have to use their wait commands. There aren’t very many things you can implement this way though. For instance, you mention making an exporter run asynchronously. How would that work if the user deleted an object mid-export, or was in the process of adding geometry to a model? Also, even though you are running asynchronously, the user is going to feel massive lagging and hiccups while they work. The suggestion above to use another copy of Maya to do stuff asynchronously is spot on. In addition to maya.standalone, there is also old school mayabatch which can be useful in some situations.
good luck,
Brett
Seconding rgkovach123: use maya.standalone. Having an artist manipulate a scene while it is being processed is a recipe for disaster, don’t even bother.
++ to the above. Python threading in Maya works but its’ rarely useful for anything that involves touching the Maya scene. It’s fine for, say, downloading files from the web or writing out a big log file without blocking. Long jobs should just run in another Maya (GUI if needed, standalone when you can for less user confusion).