Align pivot rotation to an edge

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!

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

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

    delete locatorB_aimConstraint1;

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

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

};

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

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.