Naming and renaming

During the last job I was on, we were receiving rigs from another company.
These rigs did not always match our hierarchy and naming conventions, so, part of my job was to recompile these rigs to match our conventions. One common and potentially time consuming job was the renaming of control curves.
We would receive them with naming conventions along the lines of ‘*_Ctrl_01’, ‘*_Ctrl_02’ and so on.
Renaming every control in the rig is neigh on impossible, so I wrote a script to do so!
The script I wrote was smashed together with no time for optimization but now with a little time on my hands I have rewritten it to be user friendly and fast.
Here it is, have a look!

import maya.cmds as cmds

selection = cmds.ls( sl = True)

for i in selection:
    shape = cmds.listRelatives( i, shapes = True )
    if shape == None:
        print 'No shape for ' + i + ', aborting.'
    else:
        try:
            a,b = i.split('_Ctrl')
            cmds.rename( i, a + b + '_Ctrl' )
        except:
            print 'No Ctrl in name of ' + i