Pages

Friday, April 4, 2014

Using scripting in Maya to help with selecting things

Happy Friday,

Here's a script i wrote today to help make selections in Maya.  I used this to add a prefix to all transforms and joints in a group.

Hope you find this script helpful:


//MEL
//prepare selection for renaming -- default uses entire hierarchy of single thing selected
if(size(`ls -sl`) == 1){
select -hierarchy;
select -r `ls -sl -type transform -type joint`;//only select transforms and joints
}



#Python
 import maya.cmds as cmds

sel = []
if len( cmds.ls( selection = True ) ) == 1:
    cmds.select(hierarchy = True)
    sel = cmds.ls( selection = True , type = ["transform","joint"] )
    cmds.select( sel, replace = True)


It is very helpful to use this in conjunction with Michael Comet's amazing rename tool to add prefixes on his website at (comet-cartoons dot com)

cheers,
-Nate

Inspired by
Michael Comet (comet-cartoons dot com).