Selected Category: Python

3 posts

Complex space switching Tutorial

Ever came across the situation of needing a space to work one way and in the next moment exactly the opposite way? Was your conclusion a 2nd control to avoid cycles in Maya? (Scroll to short answer) Long answer Imagine the situation of having a weapon in the rig for instance – some animators might just want the hands to follow the rifle, makes sense, right? But some animations using the same rig are made for a pistol instead – it’s understandable that your animators might want to animate the right arm instead of the weapon control. You come up with a smart way of making the left hand having a right hand space and a world space to accommodate for this. Then out of nowhere the direction says that you’ll need to support a left handed weapon animation. It gets more and more complicated and it can be very […]

OpenMaya Callbacks instead of Maya ScriptJobs

Whenever you want something to happen when your selection in Maya changes, the first thing that comes into your mind might be Maya ScriptJobs. However I find them very slow and not reliable, especially since they are wrapped in mel. Better use a callback from OpenMaya’s messaging system. This is how you do it: You will have to create a function that is called every time the selection changes. Make it run fast and with lots of error checking to avoid making your tool too slow. In your function, get the selection and evaluate what you want to do with it. The function could look something like this:

Don’t worry, you don’t have to use maya API but you can use pymel or even maya.cmds instead. In my example I just print the names of the selected nodes however I would avoid any prints as they are slowing down […]

Modify File References before they are loaded

When working on multiple projects you might want to use assets from other projects. Very often a file referencing pipeline makes this difficult though as Maya stores file references with absolute paths when you are not using Maya projects. To avoid this you can hijack the Referencing procedure with a callback.

The callback triggers any function you define. In the function you have access to the file path of the reference to do some checks and you can cancel the loading of the reference or manipulate the path to your liking. Create a function somewhere in your pipeline. Your function needs 3 parameters: parameter 1 is the return code (a boolean to approve or cancel the reference load operation) parameter 2 is the file object which holds the path and file information parameter 3 is client data which you can pass in to your function from the callback

[…]