#ctrPar
#parents the shape of the controller and keeps it on the same place
#by Daria Eremina
#17.02.2010
#DESCRITION
####################
#Create new ctrl on the top of old one with exact position.
#Now select the shape of new Ctrl by selecting New Controller and then hitting down #arrow.
#Run the script
#Go to hypergraph: Hirarchy, Turn on Shapes from display inside hyper graph.
# Delete the old Shape.
#TO RUN SCRIPT COPY PASTE BELOW 3 LINES IN PYTHON EDITOR AND RUN.
######################################################################
#import maya.cmds as de
#reload (cp)
#ctrPar();
######################################################################
#sel the shape of pretty ctr, sel the working ctr
#get the position of the cvs of the pretty ctr
#de.parent(r=1,s=1)
#get the new pos of all vrts of the pretty ctr
#snap them to the preveus positions
import maya.cmds as de
def ctrPar():
selected=de.ls(sl=1)
prettyCtrShape=selected[0]
workingCtr=selected[1]
#get cvs of the pretty ctr
prettyCvs=de.ls(prettyCtrShape+'.cv[*]', flatten=1)
#get position of cvs of the pretty ctr
allOldCvPos=[]
for cv in prettyCvs:
oldPos= de.xform(cv, q=1,worldSpace=1, t=1)
allOldCvPos.append(oldPos)
#parent shape to the working ctr
de.parent(prettyCtrShape, workingCtr,r=1, s=1)
#get new cvs
newCvs=de.ls(prettyCtrShape+'.cv[*]', flatten=1)
print allOldCvPos
print newCvs
#change their position
for cvNum in range(len(allOldCvPos)):
de.xform(newCvs[cvNum], worldSpace=1, t=allOldCvPos[cvNum])
#delete old ctr
if de.objExists(selected[1]+'Shape'):
de.delete(selected[1]+'Shape')
else:
print selected[1]+'Shape'+' doesnt exist'
No comments:
Post a Comment