View Full Version : 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?
|
|
rxgeez
08-01-2008, 04:59 AM
$variable = `getAttr cube1.translateX`;
the ` is the button under the esc key.
-k
Ah,
getAttr is the command I was looking for!
Thank you very much!
bankievr6
08-01-2008, 10:46 PM
how would you then assign that variable to an attribute?
Phlok
08-04-2008, 02:46 PM
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?
NaughtyNathan
08-04-2008, 03:27 PM
$actScale = `getAttr $objects[1].scaleZ`;
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.
:nathaN
Phlok
08-06-2008, 02:48 PM
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?
NaughtyNathan
08-06-2008, 02:55 PM
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 > )
:nathaN
Phlok
08-06-2008, 03:37 PM
Thanks for the hints. Also the "MEL for Programmers" is very helpful.
CGTalk Moderation
08-06-2008, 03:37 PM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.