------------------------------------------------------------------------------------------------------------------------------------------------

Fire my Function Attributes (FmFA) Setup
-- Ashish Dantu

Note: This is just one way of doing things and there do exist much simpler ways to accomplish this. I'm no way an expert on this topic, but this represents a work flow, which has worked for me.

Intro:

This tutorial is aimed at showing a way, to execute a series of actions, based on attribute changes. This method could be an alternative for scriptJobs (in cases where scriptJobs might be heavier on the scenes) or a button shelf (eg: match IK – FK etc..)


I've been using this method for few things, and has worked for me. Examples of where I use them are :

Okay now on to the steps:

  1. For the sake of a simple scenario, take a poly-sphere (name it: sphere) and a nurbsCircle (name it : Ctrl)



  1. Select CTRL and add attribute (enum) and say we want the attribute called “Scale2_in_” which has three attributes – X Axis, Y Axis and Z Axis. Now what we want to do is, when the attribute is set to X Axis, we want the scale of the sphere to be 2 in scale X and so on..



Once you have added the attributes, the Attribute “Scale2_in_” should show up in the channel box, when you select the CTRL. Click on it to see the three elements.




3) Now select the CTRL's shape node (select the CTRL and hit the down arrow and it wil take you to the shapeNode or select it from the attribute editor) and add attribute (enum) called “ignore_me” with three elements (name them what ever you want)...




  1. After the shape node is added with the attribute, selecting the CTRL, should show up in the channel box like so:

The idea is to have same number of elements per attribute in the transform and shape nodes. They will correspond to each other for a purpose, we will get into, soon.




5) Now open the expression editor and type the following and hit create. It creates an expression for us.



Now, here we are connecting the shape node's “ignore_me” attribute to the transform node's “Scale2_in_” attribute. This is a direct node assignment expression. This allows us to evaluate the above expression even when time doesn't change.

The second line in the above expression is – fireMyFunc() which is a global procedure which will host all our required line of code. So the idea is to fire our function, making use of the direct connection between the transform and shape node attributes.


6) Now switch the expression editor's select filter to “By script node name” and there type the following as shown in the picture below and say create. It creates a script node and change its Execute on to “open/close” set it to “before” mode.



Now what this means is we have created a script node which contains a function called fireMyFunc() and you can ask it to do anything for you.


  1. Next edit the above procedure with this code :

global proc fireMyFunc()
{
if (`getAttr Crtl.Scale2_in_`==0)
{
setAttr sphere.scaleX 2;
setAttr sphere.scaleY 1;
setAttr sphere.scaleZ 1;
}
else if (`getAttr Crtl.Scale2_in_`==1)
{
setAttr sphere.scaleX 1;
setAttr sphere.scaleY 2;
setAttr sphere.scaleZ 1;}
else if (`getAttr Crtl.Scale2_in_`==2)
{
setAttr sphere.scaleX 1;
setAttr sphere.scaleY 1;
setAttr sphere.scaleZ 2;}
}





8) Now when you input the above code and say edit, the function is now ready to do our work. Select the CTRL and keep changing the “Scale2_in_” attribute and see how the scale of the sphere is changed.





This is a small example, but this method can be used to get many sequential things done, at the change of an attribute.


8) Download an example file here > FmFA_Example.ma (Maya 6.0 - maya ascii file)
Right click and save as..

Known Issues:



I am working on the above two issues and would like to make a mel script to automate this for me soon. Hope this is of some help and would love to hear any comments, feedback or crits about this method. You can send me a mail at ashishdantu (at) yahoo (dot) com