Maya python - align pivot to selected edge


#1

Hey

I’d like to align pivot to a specific edge on an object. I know I can click “insert+edge click on edge” but I need to script it to apply to hundreds of objects to align to specific edge on each of them.

How can I do this?

I got as far as getting edge + its 2 vertexes, I was thinking the next step would be to get the 2 vertexes world position, or maybe 3 if I use 2 edges… and then align tool to x/y/z/rotate/scale/translate using these 2-3 coords. But I have a feeling I’m overcomplicating it…

Can any1 help out?

TIA


#2

Hey!
If i understood you in correct way, you need a script wich is setting your object pivot in the center of selected edge, right?
If so, here is a quick script for you (python)


#3

#4

Hey Nick

Thanks for looking in to it !

I was messing with it early today, got as far you have posted. But I’m stuck at getting orientation :- )

Say I have a plane, and I select left + bottom edge. I was hoping that I can use the bottom left vertex as my “pivot” position, and then use top vertex+right vertex as my orientation but I’m stuck at getting orientation match… Esentially using top vertex as one axis + right vertex as another axis. To ensure that pivot is aligned to edge. Not just positioned…

The post you made looks about what I did so far, but it does not cover orientation :- )

Thank you again for help ! :- )

I found this post lattely… but havent had time yet to try it > https://www.reddit.com/r/Maya/comments/4lx5cg/align_pivot_to_normal_in_code/

Regards
Dariusz


#5

So you also need to get the orientation.

I tryed first function from your link - it works well. In my case i just edited first line to make it work:
from pymel.cmds import * I changed to from pymel.core import *

Next you need to call this function with name of component. For ex:
orientManipToFace(‘pCube1.e[0]’)

as the result your object pivot will get orientation of setted component. But Maya does’t store object pivot rotation, only it’s position. So you can use bake pivot tool.