View Full Version : check if attribute is keyable?

06-11-2012, 05:43 PM
I'm pretty new to MEL and trying to make a script that automates some rather tedious tasks.

I have a for loop running through the selection and I would like parts of the script to execute only if the current object has certain attributes keyable.

It sounds simple enough, but I can't seem to figure out how to use the attributeQuery command properly with an if statement (if this is even the way to do it?).

My attempt so far looks like this:
if (`attributeQuery -node pCube1 -keyable translateX` == true){
print "translate X is keyable";

I get the same result whether or not the attribute is keyable.

Can anyone give me an example of an if structure that checks if a certain attribute is keyable?

Thanks in advance!

06-11-2012, 06:53 PM
Hmmm this is giving me some very strange behavior.
This was in the Maya Command Reference:
// Determine if an attribute is keyable //
attributeQuery -node "pCube1" -k "egRange";
// Result: 0

I was going to post some smug response like "Just check the command ref dude!". But, the attributeQuery command was only returning correct results for non-default attributes. Meaning, Translate, Rotate, Scale and Visibility all returned 1 regardless of what they are set to.
Added attributes return the correct result...which makes the whole thing so much more exciting.
Sooooo...yeah, of course you have no need for the default you should be all set now...right! :)

06-11-2012, 06:56 PM
the "getAttr" command should work for you.

getAttr -k "pCube1.translateX";

06-11-2012, 07:03 PM
Of course!
I forgot that getAttr was short for getAttributeCorrectlyForAllTheAttributesAttributeQueryDoesntWorkOn.

06-12-2012, 09:14 AM
Oh, yeah I thought it was weird I wasn't able to reproduce the examples from the documentation. AttributeQuery only working with custom attributes would explain it.

And getAttr seems to do the trick, many thanks guys!

CGTalk Moderation
06-12-2012, 09:14 AM
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.