FORUMS: list search recent posts

How to add If Else Expression to multiple objects with MEL ?

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Sinisa Culic
How to add If Else Expression to multiple objects with MEL ?
on Oct 2, 2011 at 5:24:20 pm

Hello everyone, I've been trying to get a hold of this but I'm quite new to MEL and expressions.

I created simple expression that changes visibility of object if its translate attribute changes

if (pCube1.translateX > 0)
pCube1.visibility = 1;

else
pCube1.visibility = 0;

now I need to add this expression to all shuttered objects that I created and I think it can probably be done with MEL command somehow, for example executing code on all selected objects to apply my if else expression on all of them, but I just keep getting errors.

This is probably really easy for someone who knows programming so please help :) ...thanks


Return to posts index

Steve Sayer
Re: How to add If Else Expression to multiple objects with MEL ?
on Oct 3, 2011 at 5:41:55 pm

The most compact way of doing this is probably to have one expression that operates on all the objects in question, rather than having a separate expression for each of them.

The code would have to have a list of all the objects, then iterate through each member of that list and execute the 'if/else' control for all of them.

But in order to do this you'd have to be comfortable working with string arrays and building commands from them.

The final code might look something like this:

string $list[] = `ls -type transform "pCube*"`;
for ($each in $list)
{
float $position = `getAttr ($each + ".translateX")`;
if ($position > 0)
setAttr ($each + ".visibility") 1;
else
setAttr ($each + ".visibility") 0;
}


-Steve


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]