Sunday, July 12, 2009

Ex03B_Curve_Claudia&Deborah




#####################
## Ex03B_Move Cvs of a Curve according to Locator direction
#######################

import maya.cmds as cmds
import math

#define distance between cvs and locator
def magnitude (v):
#v is a list of x,y,z values
x= v[0]
y= v[1]
z= v[2]
m= math.sqrt ( (x*x) + (y*y) + (z*z) )
return m

def distance (posPoint, posLoc):
#subtract both vectores
x1= posPoint[0]
y1= posPoint[1]
z1= posPoint[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
x= x1 - x2
y= y1 - y2
z= z1 - z2
m= magnitude ([x,y,z])
return m

#define moveToLocator function
def moveToLocator():
# A) get all the cvsNames of a curve
allCvs = cmds.ls("curve1.cv[:]", fl=1)

#create an empty list to store the points
MyCvs=[]

#get selected Locator
selLoc= cmds.filterExpand(sm=22)

#loop through cvs
for i in allCvs:
posPoint= cmds.pointPosition(i)
posLoc= cmds.pointPosition (selLoc)
d= distance(posPoint, posLoc)
print d
cmds.move (0,0,d,i,r=True)

#store the cvs in a list
MyCvs.append(cvs)

#call the function
moveToLocator()

No comments:

Post a Comment