PDA

View Full Version : Noob - PyMEL - Iterate through objects - turn off local rotation axis display


3rd Dimentia
06-06-2012, 01:05 AM
Hi, long time Max/Maxscript user trying to get into Maya/PyMel. For my first trick I'd like to be able to iterate through all selected objects and turn off any local rotation axis' that are displayed. And then maybe iterate through ALL objects in a scene and do the same thing.

So far I have been able to figure out how to iterate thru selected objects and print them.

I also know about this MEL command ToggleLocalRotationAxes


import pymel.core as pm
for obj in pm.selected():
print obj


If someone could point me in the direction of how to learn this and similar kinds of things, I would be very appreciative. Looking more for a "Teach a man to fish" than a "Give a man a fish" answer.

Then my next mission might be to try to do a toggle version where I can grab the state of the first one and toggle that and then set all other objects to be the same.

Cheers,

Cg.

NaughtyNathan
06-06-2012, 02:02 PM
The first thing to do is find out exactly what ToggleLocalRotationAxes actually is.

If you do a: whatIs on ToggleLocalRotationAxes you will find out that it isn't actually a real (internal) command, but a Run Time Command. A Run Time Command is simply an "alias" where a complex line or two of MEL code is reduced down into a single, handy-to-remember named "label". You then use the runTimeCommand command to find out what the "hidden" code is. In the case of ToggleLocalRotationAxes this simply works out as:
toggle -localAxis
and, as toggle is a real (internal) command that means there will (most likely) be a python equivalent. However, this is not ideal as toggle is a toggle and ideally you really need an explicit on/off command. Also, it doesn't seem to specify any explicit object names so this may be an issue if you want it to work on anything other than the active selection.

Fortunately for us, toggle does accept object names and also has a query mode, so you can query the current state of any given item:
mc.toggle('pCube1', query=1, localAxis=1)
# Result: 1

Finally, you should soon learn that most stuff in Maya is done with attributes on nodes. Anything that is a per-object setting is almost guarenteed to be handled by an attribute on the node. If you view the object transform in the Attribute Editor and open the "display" frame you should see an attribute labelled: Display Local Axis. If you toggle the local axis on/off using the above methods and watch this attribute you should see it check on and off. If you then manually flick this attribute on/off you should see in the Script Editor:
setAttr "pCube1.displayLocalAxis" 1;
This then tells you the attribute name in question. This means you can simply ignore all MEL commands and Run Time Commands and set this attribute on any given nodes to explicitly turn the local Axis display on or off.
import pymel.core as pm
for obj in pm.selected():
obj.displayLocalAxis.set(True)
Hope this is some help...

3rd Dimentia
06-08-2012, 05:00 AM
Thank you for your response. I am very grateful for your time. This will be big help.

Cg.

CGTalk Moderation
06-08-2012, 05:00 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.