

collection of class notes, resources and student work
#######################
## Ex03B_Move Cvs of a Nurbs according to Locator direction
#######################
import maya.cmds as cmds
import math
#define distance between PolFaces 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 (posVert, posLoc):
#subtract both vectors
x1= posVert[0]
y1= posVert[1]
z1= posVert[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 verticesNames of a plane
allVertices= cmds.ls ("pPlane1.vtx[:]", fl=1)
#create an empty list to store the points
MyVerts=[]
#get selected Locator
selLoc= cmds.filterExpand(sm=22)
#loop through vertices
for v in allVertices:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]
#find distance to Locator
posVert= cmds.pointPosition(v)
posLoc= cmds.pointPosition(selLoc)
d= distance(posVert, posLoc)
print d
cmds.move (d,3,d,v,r=True)
#store the cvs in a list
MyVerts.append(allVertices)
#call the function
moveToLocator()
#######################
## Ex03B_Move Cvs of a Nurbs 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 NurbsPlane
NurbsCvs = cmds.ls("nurbsSphere1.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 NurbsCvs:
posPoint= cmds.pointPosition(i)
posLoc= cmds.pointPosition (selLoc)
d= distance(posPoint, posLoc)
print d
cmds.move (d,d,d,i,r=True)
#store the cvs in a list
MyCvs.append(NurbsCvs)
#call the function
moveToLocator()
#####################
## 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()
![]() |
Generative Scripting I - SS09 |
Visit this group |