digital janitor - 2010-03-15 12:34:00
So now if you have read the previous entries, can you spot the difference between the two? Here is a revised script with a some differences. They almost do the same thing, but what is the 'almost' part? and which sections have I streamlined? There's even more more for Streamlining from reading the code, can you guess where?
import os
import platform
import datetime
import maya.cmds as cmds
#rename the parent based on the child name
def rename_parent(oSel):
for i in range(len(oSel)):
parent = cmds.listRelatives( oSel[i], p=True)
cmds.rename(parent[0], "%s_ZERO" % oSel[i])
#create a basic controller
def create_simple_controller(oSel):
rname = str(datetime.datetime.now()).split('.')
cmds.spaceLocator(n='null_%s_zero' % rname[1])
cmds.circle(n='circle_%s_ctrl' % rname[1], ch=False)
cmds.setAttr( "%s.rotateY" % ('circle_%s_ctrl' % rname[1]), 90)
cmds.makeIdentity('circle_%s_ctrl' % rname[1], apply=True, t=0, r=1, s=0, n=0 )
cmds.parent('circle_%s_ctrl' % rname[1], 'null_%s_zero' % rname[1])
return 'null_%s_zero' % rname[1]
# reset the object
def reset_multiple_objects(oSel):
for item in oSel:
cmds.xform(item, m=[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0])
# create a basic controller on the selected object
def create_simple_controller_on_object(oSel):
for item in oSel:
parent = item
child = create_simple_controller(item)
cmds.parent(child, parent)
reset_multiple_objects([child])
cmds.parent(child, w=True)
# align objects
def align_objects(oSel):
if len(oSel) == 2:
match = cmds.xform(oSel[1], m=True, ws=True, q=True)
cmds.xform(oSel[0], m=match)
else:
print 'too many objects'
#replace L1 with R and R1 with L
def fix_mirror_name(oSel):
for item in oSel:
if item.endswith('L1'):
new_name = item.replace('L1', 'R')
cmds.rename(item, new_name)
if item.endswith('R1'):
new_name = item.replace('R1', 'L')
cmds.rename(item, new_name)