# Align pivot rotation to an edge

**URL:** https://forum.highend3d.com/t/align-pivot-rotation-to-an-edge/341
**Category:** Maya
**Tags:** mel
**Created:** [March 19, 2013, 5:27pm UTC](https://forum.highend3d.com/t/align-pivot-rotation-to-an-edge/341 "2013-03-19T17:27:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fran-krause](https://forum.highend3d.com/user_avatar/forum.highend3d.com/fran-krause/32/78_2.png) [@fran-krause](https://forum.highend3d.com/u/fran-krause)
#### Post date: [March 19, 2013, 5:27pm UTC](https://forum.highend3d.com/t/align-pivot-rotation-to-an-edge/341/1 "2013-03-19T17:27:08Z")

</div>

Hi everybody,

I'm trying to write a script that will take a selection of two verteces (on pPlane1 for now) and realign the plane's pivot to rotate on the edge between the two selected points. When I run my current script, the location of the pivot works, but the angle is always slightly off. Any ideas on this one?

Thanks!

{  
&nbsp;&nbsp;&nbsp; string $sel[] = `ls -sl -fl -l`;

&nbsp;&nbsp;&nbsp; float $pointA[] = `pointPosition -w  $sel[0]`;  
&nbsp;&nbsp;&nbsp; float $pointB[] = `pointPosition -w  $sel[1]`;  
&nbsp;&nbsp;&nbsp; spaceLocator -p $pointA[0] $pointA[1] $pointA[2] -n locatorA;  
&nbsp;&nbsp;&nbsp; xform -cp;  
&nbsp;&nbsp;&nbsp; spaceLocator -p 0 0 0 -n locatorB;  
&nbsp;&nbsp;&nbsp; xform -cp;  
&nbsp;&nbsp;&nbsp; move -a $pointB[0] $pointB[1] $pointB[2] locatorB;  
&nbsp;&nbsp;&nbsp; aimConstraint -offset 0 0 0 -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0 locatorA locatorB;

&nbsp;&nbsp;&nbsp; delete locatorB\_aimConstraint1;

&nbsp;&nbsp;&nbsp; float $x = `getAttr locatorB.rotateX`;  
&nbsp;&nbsp;&nbsp; float $y = `getAttr locatorB.rotateY`;  
&nbsp;&nbsp;&nbsp; float $z = `getAttr locatorB.rotateZ`;  
&nbsp;&nbsp;&nbsp; print ( $x + " " + $y + " " + $z);

&nbsp;&nbsp;&nbsp; xform -ra $x $y $z pPlane1;  
&nbsp;&nbsp;&nbsp; move -a $pointB[0] $pointB[1] $pointB[2] pPlane1.scalePivot pPlane1.rotatePivot ;

};

---

<div class="post-metadata">

### Author: ![trevor-van-hoof--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@trevor-van-hoof--2](https://forum.highend3d.com/u/trevor-van-hoof--2)
#### Post date: [March 22, 2013, 2:54am UTC](https://forum.highend3d.com/t/align-pivot-rotation-to-an-edge/341/2 "2013-03-22T02:54:08Z")

</div>

What exactly do you intend to achieve? What angle is slightly off? Is it the forward vector (which for me works when running your script) or are it the other 2 vectors, which is logical because the up vector should aim to the edge normal and not [0,1,0].

Also did you freeze your plane after rotating it? This rotates the plane so that the axis matches the edge (but also... rotates the plane). With the -p flag (if I recall correctly) the plane can be forced back in place; this also means the axis does not change visually, just the rotation values do.

I currently can't imagine either of these outcomes as something useful so again, why do you need this?

Cheers,  
-Trevor

---

<div class="post-metadata">

### Author: ![fran-krause](https://forum.highend3d.com/user_avatar/forum.highend3d.com/fran-krause/32/78_2.png) [@fran-krause](https://forum.highend3d.com/u/fran-krause)
#### Post date: [April 3, 2013, 4:05pm UTC](https://forum.highend3d.com/t/align-pivot-rotation-to-an-edge/341/3 "2013-04-03T16:05:00Z")

</div>

I was trying to break up the polygons of a shape, then have them all pivot on an edge, so they could move like feathers. In the end, I just parented them to the locator, and that worked fine.
