-- aligns pivot like in Maya but better:
-- 1) to vertex or to direction between two selected vertecses
-- 2) to edge
-- 3) to face or to avarage direction of multiple faces
-- 4) if nothing is selected Script will reset pivot, wich means change from working to world
-- 5) continue press the script without any selection to switch between "Use Pivot Point Center" and "Use Selection Center" mods
-- changes only Working pivot, not actual world pivot of object
-- works with Editable poly and edit poly modifire
-- works with only one selected object
-- v 1.0
-- 24.05.2021
macroscript AlignPivotBasachi
category:"Basachi"
tooltip:"Align Pivot"
buttonText:"APB"
(
global SwitchSelCenter
fn EdgeSnap vertsOfSelEdge =
(
v1 = polyOp.getVert $ vertsOfSelEdge[1]
v2 = polyOp.getVert $ vertsOfSelEdge[2]
p = Point() --is
p.dir = v1 - v2 --it
WorkingPivot.setTM p.transform -- genious
delete p -- ?
toolMode.coordsys #working_pivot
setCoordCenter #Selection
SwitchSelCenter = false
)
fn FaceSnap SelFeces =
(
FaceNormal = [0,0,0]
for face in SelFeces do
FaceNormal += polyop.getFaceNormal $ face
p = Point() --is
p.dir = FaceNormal --it
WorkingPivot.setTM p.transform -- genious
delete p -- ?
toolMode.coordsys #working_pivot
setCoordCenter #Selection
SwitchSelCenter = false
)
fn ResetPivotToWorld =
(
toolMode.coordsys #world
if SwitchSelCenter == true then
(
if getCoordCenter() == #local then setCoordCenter #Selection
else setCoordCenter #Local
)
else SwitchSelCenter = true
)
case classof (modPanel.getCurrentObject()) of
(
Editable_Poly :
(
case subobjectLevel of
(
1 :
(
selVert = polyop.getVertSelection $ as array
if selVert.count == 0 then ResetPivotToWorld()
if selVert.count == 1 then FaceSnap (polyop.getFacesUsingVert $ selVert as array)
if selVert.count == 2 then EdgeSnap selVert
)
2 :
(
SelEdge = polyop.getEdgeSelection $ as array
if SelEdge.count == 0 then ResetPivotToWorld()
if SelEdge.count == 1 then EdgeSnap (polyop.getVertsUsingEdge $ SelEdge[1] as array)
)
4 :
(
SelFaces = polyop.getFaceSelection $ as array
if SelFaces.count == 0 then ResetPivotToWorld()
else FaceSnap SelFaces
)
5 :
(
SelFaces = polyop.getFaceSelection $ as array
if SelFaces.count == 0 then ResetPivotToWorld()
else FaceSnap SelFaces
)
default: ResetPivotToWorld()
)
)
Edit_Poly :
(
if ($ as string) != "$selection" then
(
case subobjectLevel of
(
1 :
(
selVert = $.modifiers[#Edit_Poly].GetSelection #Vertex as array
if selVert.count == 0 then ResetPivotToWorld()
if selVert.count == 1 then FaceSnap (polyop.getFacesUsingVert $ selVert as array)
if selVert.count == 2 then EdgeSnap selVert
)
2 :
(
SelEdge = $.modifiers[#Edit_Poly].GetSelection #Edge as array
if SelEdge.count == 0 then ResetPivotToWorld()
if SelEdge.count == 1 then EdgeSnap (polyop.getVertsUsingEdge $ SelEdge[1] as array)
)
4 :
(
SelFaces = $.modifiers[#Edit_Poly].GetSelection #Face as array
if SelFaces.count == 0 then ResetPivotToWorld()
else FaceSnap SelFaces
)
5 :
(
SelFaces = $.modifiers[#Edit_Poly].GetSelection #Face as array
if SelFaces.count == 0 then ResetPivotToWorld()
else FaceSnap SelFaces
)
default: ResetPivotToWorld()
)
)
else messageBox "only one object allowed" beep: 0
)
default: ResetPivotToWorld()
)
)