/********************************************************************************************************************************************
Rotation Order Tool created by Alex Velez on 7/6/2011 Questions, Comments: alexvelez[at]email.com
V.1: Allows changing the rotation axis of multiple seelcted objects in on step. It preserves the original transformation information
This tool also allows you to copy the rotation order of one object onto another. Very handy for setting up controllers to match bones. 
I will need to refactor this code, its a bit messy but I needed soemthing very quick.

Usage: For multiple selection changes simply select all the objects who's rotation order you want to chnage and select the desired 
rotation order from the dropdown list

To copy: Select the object you want to copy from FIRST. Then select the other object. Hit the copy button. If there are mismatched controllers, 
meaning one is a rotation list, and the other is a regular rotation controller. It will look for the first Euler controller in the Rotation List.

To install just drag the mcr file into autodesk\maxversion\ui\macroscripts folder. Add the tool to a toolbar. You'll find it under alex tools
*********************************************************************************************************************************************/
macroScript av_RotAxis
category:"Alex Tools"
tooltip:"Rot Order Tool"
buttontext:"Rot Order"
(
try(destroydialog rotAxisRoll)Catch()
rollout rotAxisRoll "Rot Order" width:120 height:120
(
	group "Multi Sel Change"
	(
		dropDownList roOrderDL "Rotation Order" pos: [20, 20] width: 80 items:#("XYZ","XZY","YZX","YXZ","ZXY","ZYX","XYX","YZY","ZXZ")
	)
	
	group "Copy Rot Order"
	(
		button copyRotBtn "Copy Rot Order!" pos:[10,85] width:100 height:20 toolTip:"links the parent and child slots together"
	)
	
	on roOrderDL selected i do
	(
		for s in selection do
		(
			if classof s.rotation.controller == Rotation_List do
			(
				for c = 1 to s.rotation.controller.count do
				(
					If (hasProperty s.rotation.controller[c] "axisorder") == true do
					(
						tempTM = s.transform
						s.rotation.controller[c].axisorder = i
						s.transform = tempTM
					)--end if 
				)--end forr loop
			) --end if rot list
			
			If (hasProperty s.rotation.controller "axisorder") == true do
			(
				tempTM = s.transform
				s.rotation.controller.axisorder = i
				s.transform = tempTM
			)--end if hasproperty
		)--end selection for loop
	)--end event handler
	
	on copyRotBtn pressed do
	(
		local selOneCTRL
		local selTwoCTRL
		if selection.count > 1 and selection.count <3  do
		(
			if classof selection[1].rotation.controller == Rotation_List do
			(
				for i = selection[1].rotation.controller.count to 1 by -1 do
				(
					If (hasProperty selection[1].rotation.controller[i] "axisorder") == true do
					(
						selOneCTRL = selection[1].rotation.controller[i]
						exit
					)
				)
			)
			
			if classof selection[2].rotation.controller == Rotation_List do
			(
				for i = selection[2].rotation.controller.count to 1 by -1 do
				(
					If (hasProperty selection[2].rotation.controller[i] "axisorder") == true do
					(
						selTwoCTRL = selection[2].rotation.controller[i]
						exit
					)
				)
			)
			
			if  (hasProperty selection[1].rotation.controller "axisorder") == true do
			(
				selOneCTRL = selection[1].rotation.controller	
			)
			
			if  (hasProperty selection[2].rotation.controller "axisorder") == true do
			(
				selTwoCTRL = selection[2].rotation.controller	
			)
			
			If (hasProperty selOneCTRL "axisorder") == true and (hasProperty selTwoCTRL "axisorder") == true then
			(
				tempTM = selection[2].transform
				selTwoCTRL.axisorder = selOneCTRL.axisorder 
				selection[2].transform = tempTM
			)--end if hasproperty
			else
			(
				Messagebox "Your controllers dont match. \nOne has a rotation order the other does not." Title:"Error Wil Robinson!"
			)
		)--end if selection count
	)--end event handler
		
)
createdialog rotAxisRoll  120 120  
)