This is the scripting with probls
## Ex03B_Move Curve Cvs according to Locator direction
#####
import maya.cmds as cmds
import math
#get names of selected objects on Stage
#first select the objects
selObj= cmds.ls(sl=1)
print selObj
#find position of this two objetcs
obj1= selObj[0] #this is for locator1
obj2= selObj[1] #this is for curve1
print obj1
print obj2
pos1= cmds.pointPosition(obj1)
pos2 = cmds.pointOnCurve(obj2)
print pos1
print pos2
#find distance between two objects
d= distance (pos1,pos2)
print d
#move all vertices of obj2 10 times in direction to obj1
# select all vertices of obj2
allCvs = cmds.ls("curve1.cv[:]", fl=1)
# I dont know how to continue....
Here is the script to move the curve position according to loc1 direction
## Ex03B_Move Curve according to Locator direction
#####
import maya.cmds as cmds
import math
#get names of selected objects on Stage
#first select the objects
selObj= cmds.ls(sl=1)
print selObj
#find position of this two objetcs
obj1= selObj[0] #this is for locator1
obj2= selObj[1] #this is for curve1
print obj1
print obj2
pos1= cmds.pointPosition(obj1)
pos2= cmds.pointOnCurve(obj2)
print pos1
print pos2
#find distance between two objects
d= distance (pos1,pos2)
print d
#move obj2 4 times in direction to obj1
# first get vectors between obj2 and obj1
v= vectorBetweenPoints(pos1,pos2)
# get the unit of vector v
dir= unit(v)
#move 4 units in dir obj1
newPos= move (dir,4)
#move obj2 to that position
cmds.move (newPos[0], newPos[1], newPos[2], obj2)
This is the exercise of extruding faces of a polygon according to the distance of a Locator.
### Ex03B ######
## Vector Functions
import maya.cmds as cmds
import math
import random
########### extrude the faces of a polygonal object
# according to its distance to a certain
# locator
def ExtrudeToLocator():
"Extrude based on a distance of a certain Locator"
#get selected Poly and selected Locator
selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]
#get all faces of the Poly
allFaces= cmds.ls(selPoly + ".f[:]", fl=1)
#start a loop through all faces
for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
# find the center of the face
xs= 0
ys= 0
zs= 0
#loop through vertices
for v in vertex:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]
xs= xs + x
ys= ys + y
zs= zs + z
centerX= xs/len(vertex)
centerY= ys/len(vertex)
centerZ= zs/len(vertex)
#check by placing a Locator
cmds.spaceLocator(p=(centerX, centerY, centerZ))
#find distance to Locator
posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d)
#extrude to locator
ExtrudeToLocator()
Hi Claudia,
ReplyDeleteYou have some mistakes, the main one related to how you use the command pointOnCurve. It does not make sense (read the help about it). You actually don't need to use it, as the points of the curves you are going to move are your vertices. If you have your vertices (which you have in your last line), do a loop through them, and that is where you are going to get the poinPosition of the CV and get the distance between the position of the cv and the position of the locator. Then you make the transformations you want!