Hotkey: Toggle Local Axes Together

Here’s another quick little hotkey. I wanted something to toggle the display of a joints local rotation axis… now I know there is a simple one liner that is already sitting in the hotkey editor, but, if your selection contains some objects with local rotation axis on and some with it off, it’s unlikely the desired effect is to switch the offs to on and the ons to off (are you following me?). So this may be overkill, but here it is:


'''Hotkey: Toggle Local Axes Together'''
import maya.cmds as cmds

axes_on, axes_off = [], []
selection = cmds.ls(selection=True)
for selected in selection:
    if cmds.toggle(selected, query=True, localAxis=True):
        axes_on.append(selected)
    else:
        axes_off.append(selected)

if not axes_on:
        cmds.toggle(localAxis=True, state=True)
elif not axes_off: 
        cmds.toggle(localAxis=True, state=False)
else: cmds.toggle(localAxis=True, state=False)  

Hotkey: Toggle Object/World Modes

A quick little hotkey for Maya. It simply toggles between the world and object modes of the move, rotate, and scale tools.

It came about after a request from a friend who was getting frustrated whilst working on a task which had him switching between modes a lot. Hopefully others may find it useful as well so feel free to grab the script below, paste into your hotkey editor and assign a key (make sure you have the language set to Python). And I’m sure this could be made more elegant, so if you have a different way of doing it I’d love to see!

'''Simple hotkey command to toggle between object and world modes for
Move, Rotate, and Scale contexts'''
import maya.cmds as cmds

# I want to toggle independently based on what context is being used,
# So the first thing I need to do is get the current context.
current_context = cmds.currentCtx()

# Then there is a different if/else statement depending on context.
if current_context == 'moveSuperContext':
    mode = cmds.manipMoveContext( 'Move', q=True, mode=True )
    if not mode:
        cmds.manipMoveContext( 'Move', e=True, mode=2 )
    else:
        cmds.manipMoveContext( 'Move', e=True, mode=0 )
        
if current_context == 'RotateSuperContext':  
    mode = cmds.manipRotateContext( 'Rotate', q=True, mode=True )
    if not mode:
        cmds.manipRotateContext( 'Rotate', e=True, mode=1 )
    else:
        cmds.manipRotateContext( 'Rotate', e=True, mode=0 )
     
if current_context == 'scaleSuperContext':
    mode = cmds.manipScaleContext( 'Scale', q=True, mode=True )
    if not mode:
        cmds.manipScaleContext( 'Scale', e=True, mode=2 )
    else:
        cmds.manipScaleContext( 'Scale', e=True, mode=0 )

As a quick side, for the same friend I’m also working on a little widget that can be used to save and recall custom axis orientation in a single click, when it’s ready to go I’ll post it up!