List Color Attributes

heya guys:)

I want to optimise an old script, so i was wondering, what is the best way (performance wise)
to list only the color attributes of a node (for example a lambert -> color, ambient etc)? The listAttr
doesnt seem to have this filter unfortunately... is tehre another way with MEL? or maybe python?

thanks in advance:)

The listAttr -multi shoud be useful.

Well you cant actually know if something is a color or not. Not really since maya dont actually care wether its a color or not in most cases so it dot tell you anything. But a multi attribs with three children of type float are all the same thing irresepectible of are they defined as colors or not.

thanks for the replies... though, the multi returns many useless attributes (including split out colors into R, G, B ). I need only the color (or 3 channel attributes ) ones, or at least the fewer unneeded returns as possible (I loop through hundreds of nodes, query the attributes, check them and modify them if they are colors... so if the node attributes list is too big things get quite slow eh). There must be a way to accelerate this eh?

thanks again

Umm you really dont want to do this in script. Its not very handy to do this, theres lot more to consider.

For example let us suppose you adjust gamma globally on all your nodes. Do you really think finding all the things that are colors helps?

I mean many nodes such as multiply divide are 3 float multi attribs but they are not colors. However they MAY represent a color in the final product nevertheless by implication. Worse even non multi attributes might represent a color down the stream. So how do you decide at what point to put in the manipulation? Well you could just nodalize the connection and just manipulate true sources. But then youd have to decide what a true source is and make sure NOT to affect parents in its graph.

Now even worse then that you cant possibly know if the source of this is a target of a totally legitimate sure to be colors you want to change, in which case you DONT want the gamma node input, but then again you might because the inner calculation in between might need to be gamma independent which means you need 2 gamma nodes.

Second problem, everything being equal in maya makes it hard for yu to decide if a color attribute is actually being used a s a color, or just a float source for a transform for example. Worse it could be used as BOTH at the same time.

So making this idiot proof is a bit hard. But yes you can ask maya if something was created as float3 variable:

getAttr -type "lambert1.color";
// Result: float3 //

EVEN WORSE: all vertex locations are of type float3 and they are 2 times in the scene

But the API does know if they were implicitly created as colors or not, but again this info isn't as revealing as you might think.

As joojaa said, there is no way to determine if an attr is a colour, however you can normally take a fairly good guess...

CODE
proc int guessIfAttrIsColour(string $node,string $attr)
{
  string $attrR = $attr + "R";
  string $attrG = $attr + "G";
  string $attrB = $attr + "B";

  if(  getAttr -type ($node+"."+$attr) == "float3")
  {
    if( attributeExists($attrR,$node) &&
        attributeExists($attrG,$node) &&
        attributeExists($attrB,$node) )
       return 1;
  }
  return 0;
}

$nodes = ls;
for($node in $nodes)
{
  $attrs = listAttr -o -v -m $node;
  for($attr in $attrs)
  {
    if(guessIfAttrIsColour($node,$attr))
    {
      print ($node + "." + $attr + " might be a colour\n");
    }
  }
}

of course, in the API you could add an attr:

attr
attrX
attrY
attrZ

and still set it to be used as a colour, in which case the above script would never work.