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 […]
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:
from maya import OpenMaya
#function to execute when selection changes
def maya_selection_changed(*args, **kwargs):
sel = OpenMaya.MSelectionList()
selection_iter = OpenMaya.MItSelectionList(sel)
obj = OpenMaya.MObject()
# Loop though iterator objects
while not selection_iter.isDone():
# Now we can do anything with each of selected objects.
# In this example lets just print path to iterating objects.
dagPath = OpenMaya.MDagPath.getAPathTo(obj)
except RuntimeError, err:
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 […]
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
def callbackFunction(retCode, fileObject, clientData):
# printing the original file path
print "Original file path %s" % fileObject.rawFullName()
# create a variable for the new file path
# maybe create some logic for that or even a condition whether to
# manipulate the path or keep the existing one
newFilePath = "C:/tmp/newFile.ma"
# set the file path to be loaded if you want to modify it
# here you can define whether the file should be loaded or
# whether the reference should be skipped