Pymel HowTo place a secondary object along Polygon Edge

Hey,

    I am new to Pymel. To begin with, I was trying to place a cylinder along all  the edges of a polygon. So First I moved the cylinder to the center of two vertices.Well after that I have problem in finding out the rotation angles required to align the cylinder along the edges. Basically this is a math problem.

Attempts made; If v0 and v1 are the vertices. I found out the vector joining these two points. Also I have the vector of the cylinder, I need to rotate the vector along the vertex vector.

So first I found out of the angle between these two vectors. But the angle obtained is always 90 degree.

Can anyone throw some ideas about this.

(Redirecting to Google Groups)

Thank You
Nano Pavan

Correct me if I’m wrong, but it sounds like you’re trying to do something similar to a 2 Points To 2 Points snap? If that’s the case, I might recommend you check the snap2PointsTo2Points.mel script located in scripts/startup, that might give you some ideas, or you could just port the core to pymel and go from there.

Another way, albeit hacky…

import maya.cmds as mc
import maya.OpenMaya as om

def edgeToCyl(edge):
	radius = 2
	vtx = mc.filterExpand(mc.polyListComponentConversion(edge,fe=1,tv=1), ex=1,fp=1,sm=31);
	p0 = om.MPoint(* mc.pointPosition(vtx[0],w=1))
	p1 = om.MPoint(* mc.pointPosition(vtx[1],w=1))
	EV = p1-p0	

	object = mc.polyCylinder(radius=radius, height=EV.length())
	mc.move((p0.x + p1.x) / 2, (p0.y + p1.y) / 2, (p0.z + p1.z) / 2 ,object)

	tempTarget = mc.spaceLocator()
	mc.move(p1.x, p1.y, p1.z,tempTarget)
	mc.delete(mc.aimConstraint(tempTarget, object, aimVector=(0,1,0)),tempTarget )

edgeToCyl('pCube1.e[0]')

Thank You for the post.

My approach was more mathematical one.

After I get the edge vector. I found the vector angle w.r.t origin and then Euler rotation for the cylinder. 

Can you please provide some comments on your code.

I understood how to moving the cylinder to the center of the object.

After that is not clear.

Thank You again.

After moving the cylinder, I set up a temporary object, tempTarget (a locator) and position it on one of the points. The last line creates an aimConstraint which points the cylinder’s y axis at the point. This aimConstraint creation is wrapped up in a delete command together with the tempTarget so it leaves it nice and tidy.

Not very mathematical, nor very quick but it offers another way of looking at the problem if you want to avoid messing about with anything more than simple vector math.