Making a rename tool by python for Maya


#1

Hi,
Trying to make rename tool for Maya. this is the task and below is the code.Please let me know if you have any idea to help.
Thank you

1- a list of maya objects of common or random objects.
2- object types as an optional parameters to rename only specific types.
3- a new name string
4- using adding parameter (01,001,0001,etc)
5- UI

import maya.cmds as cmds

def UI():
if cmds.window(‘renameTool’, exists = True):
cmds.deleteUI(‘renameTool’)

myWin = cmds.window('renameTool')
cmds.columnLayout()
cmds.text(label = 'This is a renaming tool, code by Emad Tayefeh (emad.tayefeh@gmail.com)')
cmds.text(label = 'Renaming structure: ')

cmds.text( label='a_name' )
a_name = cmds.textField()

cmds.text( label='a_padding' )
a_padding = cmds.intField()

cmds.text(label='a_suffix')
a_suffix = cmds.textField()

cmds.textField( a_name, edit=True, enterCommand=('cmds.setFocus(\"' + a_name + '\")') )
cmds.intField( a_padding, editable=True )
cmds.textField( a_suffix, edit=True, enterCommand=('cmds.setFocus(\"' + a_suffix + '\")') )

cmds.button(label = 'Rename' ,  command = 'myRenameFunc()')
cmds.showWindow('renameTool')

a_name = str(a_name)
a_padding = int(a_padding)
a_suffix = str(a_suffix)

def myRenameFunc():

listobj = cmds.ls(selection=True)
for count,obj in enumerate(listobj):
   cmds.rename(obj, a_name + "_" + str(count + 1).zfill(a_padding) + "_" + a_suffix)

UI()


#2

Hello there,

There are renaming scripts available at highend3d.com. You can use them as a reference. I use quick rename tool and there are others available at the website. The one I use is written in MEL but you can easily convert it.

I don’t have anything else to advise you on sorry.