Posts

Showing posts from February, 2019

Useful Python Tricks!

#1 – To get rid of redundant/repetitive words itemList = cmds.ls ('pasted__*') for item in itemList: newName = item.rpartition('pasted__')[-1] cmds.rename(item, newName) #2 – Change the first lower case to upper case import maya.cmds as cmds for obj in cmds.ls(sl=1): a = obj[0].upper() new = a+obj[1:] print new cmds.rename(obj, new) #3 – Select the shapes within ‘Transform’ groups import pymel.core as pm cmds.select(pm.listRelatives( cmds.ls (sl=1)[0],shapes=True, ad=True)) #4 – Create a new camera from the perspective import maya.cmds as cmds cameraTransform = cmds.modelEditor(cmds.getPanel(withLabel = 'Persp View'), query = True, camera = True) cameraShape = cmds.listRelatives(cameraTransform, type = 'camera')[0] newCameraName = '%s_NEW' % cameraTransform cmds.duplicate(cameraShape, name = newCameraName) cmds.showHidden(newCameraName) cmds.select(newCameraName, replace = True)