In MEL scripts, use the getAttr and setAttr commands to get and set attribute values:
sphere -name "Brawl"; print(getAttr("Brawl.scaleY")); float $ys = `getAttr Brawl.scaleY`; setAttr("Brawl.scaleY", $ys * 2);
You can get or set an element of a particle vector or float array using the getParticleAttr and setParticleAttr commands.
float $Tmp[] = `getParticleAttr -at position FireShape.pt[0]`; vector $particlePosition = <<$Tmp[0], $Tmp[1], $Tmp[2]>>; setParticleAttr -at position -vv 0 0 7 FireShape.pt[0];
In animation expressions, you do not use the getAttr and setAttr commands. You can simply use the node/attribute name in expressions:
myCone.scaleY = mySphere.scaleX * 2
If two objects in a scene have different parents, they're permitted to have the same name. For example, a scene could have two spheres named doughnutHole if one sphere has a parent of GroupA and the other sphere has no parent at all.
In these cases you can’t specify an object using only its name, because Maya wouldn’t know which object you were talking about. MEL will print the following error:
ERROR: Which one?
If Maya can’t automatically figure out which object you mean, you need to specify a unique path to the object.
A path tells Maya how to find the exact object you want by listing the steps through the hierarchy it needs to take to find the object. For example:
In this example, the full path of the hand object is:
|character|shoulder|arm|hand
The vertical bar character (|) indicates that the object to the left of the character is the parent of the object to its right:
sphere -name doughnutHole; group -name GroupA; sphere -p 3 0 0 -name doughnutHole; setAttr doughnutHole.scaleY 3.3; // ERROR: Which one? setAttr GroupA|doughnutHole.scaleY 3.3;
To specify an object that does not have a parent, type a vertical bar before the object name:
setAttr |doughnutHole.scaleY 0.3;
You can specify the full pathname of an object by giving the names of all the parents in an object hierarchy. Just separate each parent with a pipe character.
group -name GroupB GroupA; setAttr |GroupB|GroupA|doughnutHole.scaleY 1;
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License