align verts on hotkey

I have been trying to get a script that aligns vertices along and axis using the last selected vert as center and using modkeys to determine the direction.

I really need some help to get it functioning

macroScript flattentest2 category:"tools" toolTip:"flattentest2"
(
 
	(
function getModKey =
	(
	local resultData = #none
 
	if ( (not keyboard.shiftPressed) and (not keyboard.controlPressed) and (not keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #none
	else if ( (keyboard.shiftPressed) and (not keyboard.controlPressed) and (not keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #shift
	else if ( (not keyboard.shiftPressed) and (keyboard.controlPressed) and (not keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #ctrl
	else if ( (not keyboard.shiftPressed) and (not keyboard.controlPressed) and (keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #alt
	else if ( (keyboard.shiftPressed) and (keyboard.controlPressed) and (not keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #shiftctrl
	else if ( (not keyboard.shiftPressed) and (keyboard.controlPressed) and (keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #ctrlalt
	else if ( (keyboard.shiftPressed) and (keyboard.controlPressed) and (keyboard.altPressed) and (not keyboard.escPressed) ) then
		resultData = #shiftctrlalt
 
	return resultData
	)
 
 
fn getObj =
	(
	if selection.count == 1 then obj = selection[1] else undefined --if selection count is one then obj= selected
	)
 
 
fn getoffset x y =
	(
		d = y-x
 
		if x > y then
		(
			if d > 0 then d else -d
		)
		else
		(
			if d > 0 then -d else d
		)
	)
 
 
if getObj() != undefined do with undo "Align Vertices" on with redraw off --if object is not undefined
	nKey = getModKey() 
	testModifier = classOf $
			(	
			if testModifier == Editable_Poly then 
					(
						selectedVert = polyOp.getVertSelection obj as array
					)
			else if testModifier == PolyMeshObject do
					(
						selectedVert = obj.Edit_Poly.GetSelection #Vertex as array
					)	
		max undo 
 
	testModifier = classOf $
			if testModifier == Editable_Poly then 
					(
						selectedVert2 = polyOp.getVertSelection obj as array
						firstV= for i in selectedVert where finditem selectedVert2 i == 0 collect i
						firstVXYZ = polyOp.getVert obj firstvert[1] 
					)
			else if testModifier == PolyMeshObject do
					(
						selectedVert2 = obj.Edit_Poly.GetSelection #Vertex as array
						FirstV = for i in selectedVert where finditem selectedVert2 i == 0 collect i
						FirstVXYZ = obj.GetVertex firstvert[1] 
					)	
 
					print FirstV
					print FirstVXYZ
		max redo
			)
 
 
		vertSel = obj.selectedVerts  --selected vertlist
 
			--Get the intended plane axis
			case nkey of (
					#none: n = [0,0,0]  
					#shift: n = [1,0,0]  --x?
					#ctrl:  n = [0,1,0]  --y?
					#alt:   n = [0,0,1]  --z?
								)
 
			polyop.moveVertsToPlane obj vertSel n 0.0  --flatten  selection, vertlist, n=xy, orz 
 
			vert1 = pGetVert obj vertSel[1].index --defines vert1 as average of vert
 
			case nkey of (--offset based on average vs first vert
					#none: offset = [0,0,0]  
					#shift: offset = [(getoffset FirstV.x vert1.x),0,0]  -x?
					#ctrl:  offset = [0,(getoffset FirstV.y vert1.y),0] --y?
					#alt:   offset = [0,0,(getoffset FirstV.z vert1.z)] --z?
							)
 
			polyop.moveVert obj vertSel offset --move selcted vert selection by offset
	)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
greyocto's picture

lol maiuu beat me to it with

lol maiuu beat me to it with his new scriptpack

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.