[MEL] Beginner - Script to move object pivot to vertex


#1

Heyas,

I have several hundred hair objects created using paint effects and converting to individual meshes.

Is there a simple script I can use to move the pivot of each hair/object to its respective vtx[0] ? Preferably just by selecting all of the hairs and running the script, but individually would be useful too.

Thanks,
Regan


#2

Modify all nurbsCurves on the scene:

for curve in pm.ls(type="nurbsCurve"):
    transform = curve.getParent()
    firstCv = curve.getCVs()[0]
    transform.rotatePivot.set(firstCv)
    transform.scalePivot.set(firstCv)

#3

Thanks for that haggi. :slight_smile:

They are actually polygon objects, so I cobbled this together from what I could find online


$selection = `ls -sl -l`;
for($object in $selection)
select $object.vtx[0];
hilite $object;

{
$vert = `ls -sl`;
$obj = `listRelatives -p (ls("-o", "-sl"))`;
$xyz = `pointPosition $vert[0]`;
move $xyz[0] $xyz[1] $xyz[2] ($obj[0] + ".scalePivot") ($obj[0] + ".rotatePivot");
select $obj;
};

I couldn’t get it to work on multiple selections though.

.


#4

Try this


proc movePivotToVert()
{
    string $selections[] = `ls -sl`;
    for($object in $selections)
    {
        select ($object + ".vtx[0]");
        $vert = `ls -sl`;
        $obj = `listRelatives -p (ls("-o", "-sl"))`;
        $xyz = `pointPosition $vert[0]`;
        move $xyz[0] $xyz[1] $xyz[2] ($obj[0] + ".scalePivot") ($obj[0] + ".rotatePivot");
    }
  
  select -r $selections;    
}

movePivotToVert();

#5

And I suggested pyton even if you explicilty pointed out in your subject that it is a mel question. Sorry.
There is no need to select anything. Most commands can be used with a object name as argument:

string $objlist[] = `ls -sl -l`;
for( $obj in $objlist)
{
    float $pos[] = `xform -q -ws -t ($obj + ".vtx[0]")`;
    move $pos[0] $pos[1] $pos[2] ($obj + ".scalePivot") ($obj + ".rotatePivot");
}

#6

That did the trick, thanks a lot! :slight_smile:

No worries. Thanks. :slight_smile: