Tuesday, April 26, 2011

Selection, Renaming, and Iteration.. Oh My!

Thought i would share some of the handy scripts i have made why making rigs for games. Some of these are short, but have saved me tons of time.

import pymel.core.general as pmg
import pymel.core.windows as pmw
import pymel.core.rendering as pmr
import pymel.core.modeling as pmm
import pymel.core.animation as pma
import pymel.core.system as pms
import maya.cmds as cmds
import maya.mel as mm

This one is handy, will rename some objects and make the last bone in the chain "Nub". This needs some adjustment to be able to handle number padding, but its a goood start.

def renameBones(boneName):
# need to add number padding as a function

numStart = 1
selection = pmg.ls(sl=True)
for obj in selection:
pmg.select(obj, hi=True, r=True)
nubTest = pmg.ls(sl=True)
# Check to see if node has children, if not name it 'Nub'
if len(nubTest) == 1:
nubArray.append(obj)
replaceName = boneName +'Nub'
pmg.rename(str(obj) , replaceName)
continue
replaceName = boneName + '0' + str(numStart)
pmg.rename(str(obj) , replaceName)
numStart += 1

I needed a quick way to select all the joints in a chain, and ignore all the other constraints and nonsense that can get added in there.

def sJoints():
pmg.select(hi=True)
origSelection = pmg.ls(sl=True)
joints = []
for obj in origSelection:
if pmg.nodeType(str(obj)) == 'joint':
joints.append(obj)
pmg.select(joints, r=True)

Iterator:

I found that when creating custom rigs I had to iterate alot through attributes here is a pretty quick solution for doing common things through attributes. Basically making an array out of each and running through them.

for attr in ['t', 'r','s']:
for axis in ['x','y','z']:
pmg.setAttr(str(objName)+'.' + attr + axis , lock=True, keyable=False)

No comments:

Post a Comment