Noob: How to query attribute and store as variable?


Hi everybody!

I’m having trouble figuring out how to take an attribute, such as object1.translateX
-and storing that value as an attribute.
Say I’ve got a cube that is +4 in translateX.

What command would I use like-

$variable = cube1.translateX

to store that attribute as a variable?


$variable = getAttr cube1.translateX;

the ` is the button under the esc key.




getAttr is the command I was looking for!

Thank you very much!


how would you then assign that variable to an attribute?


In my script, there is a sytax error thrown using a construction just as the one stated here:

 $actScale = `getAttr $objects[1].scaleZ`;

$objects[1] conatins a simple polygon sphere.

What did I do wrong?


.scaleZ is not an attribute (or method!) of the variable “$object[1]”, but rather an attribute of the contents of the string (e.g. “pCube1”), so it must be constructed and concatanated as a string. (not sure I’ve explained that very well but…)

$actScale = getAttr ($objects[1] + ".scaleZ");

you’re combining (catenating) a string variable and a literal string and gettingAttr on the combined result.



I found a fix for that matter, but it still stays a little unclear to me. If I had an array in C++, e.g. I defined a class called obj and then I define an array that can contain elements of the type obj, called array.

Let’s say Obj provides a public method DoSomething(), a public int variable MyInt and my array has been filled with objects of type obj.

Then operations such as array[i].DoSomething() or int j = array[i].MyInt are usually possible.

What’s the difference with MEL in that case?


MEL has NOTHING like this. MEL is the most basic scripting language. it has no object orientated features, no classes, no methods, no structures, nothing.

it has only basic types: int, float, string, vector, and a 1D array version of each and that IS IT…!

(it also has a matrix type too)

you can set a variable and read/use it. that’s pretty much it. you can’t really do anything sophisticated with them.

have a read of “MEL for Programmers” in the Maya docs (Using Maya > General > MEL and Expressions > Background > )



Thanks for the hints. Also the “MEL for Programmers” is very helpful.


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.