-- by Christian Rüsseler -- www.cral.de macroScript crAlignPivotToSelection category:"CR" buttonText:"align Pivot to selection" toolTip:"align Pivot to selection" Icon:#("SW_DynInt",1) ( try ( if (selection.count != 0) then ( if subobjectLevel == 0 or subobjectLevel == undefined then for i in selection do (i.pivot = ((i.max + i.min)/2)) else ( delta = [0,0,0] local theType = classOf (modPanel.getCurrentObject()) if theType == Editable_Poly then ( local A = Filters.GetModOrObj() local currentVSelection = A.GetSelection #Vertex A.ConvertSelection #CurrentLevel #Vertex for verts in $.selectedVerts do delta += verts.pos delta /= $.selectedVerts.count A.SetSelection #Vertex currentVSelection ) else if theType == Edit_Poly then ( local currentVSelection = (modPanel.getCurrentObject()).GetSelection #Vertex (modPanel.getCurrentObject()).ConvertSelection #CurrentLevel #Vertex local newSelection = (modPanel.getCurrentObject()).getselection 1 for verts in newSelection do ( delta += (modPanel.getCurrentObject()).getvertex verts ) delta /= (newSelection as Array).count (modPanel.getCurrentObject()).SetSelection #Vertex currentVSelection ) else if theType == line or theType == SplineShape then ( local spl = selection[1] local selectedKnots = 0 for s = 1 to (numSplines spl) do ( if (knots = getKnotSelection spl s).count != 0 do ( selectedKnots += knots.count for k = 1 to knots.count do ( delta += getKnotPoint spl s ((getKnotSelection spl s)[k]) ) ) ) delta /= selectedKnots ) $.pivot = delta ) ) ) Catch () )