macroScript ReduceYourTransformKeys category:"Craig's Tools"
(
	rollout RLT_ReduceKeys "Reduce Transform Keys"
	(
		group "Reduce Your Transform Keys"	
		(
			label lab1 "For the currently selected objects..." align:#left

			spinner SP_Threshold "Threshold of Change" range: [0.0,10.0,0.1] align:#left fieldwidth:25 type:#float
			spinner SP_Duration "Time Step Samples - frames" range: [0.0,2.0,1.0] align:#left fieldwidth:25 type:#float
			spinner SP_Range_STRT "Start Frame" range:[-1000,1000,animationrange.start] type:#integer align:#left fieldwidth:25
			spinner SP_Range_End "End Frame" range:[-1000,1000,animationrange.end]  type:#integer align:#left fieldwidth:25
			
			radiobuttons RB_KeyAtZero "Keep a key at frame 0?" labels:#("No, thanks","Yes, please" ) default:1
			radiobuttons RB_KeyAtEnd "Keep a key at End Frame?" labels:#("No, thanks","Yes, please") default:1
			
		)

	button BTN_ReduceKeys "Reduce Your Keys"

		group "Credits"
		(
			label lab2 "Written by Craig P Miller" align:#left
			hyperlink H_link1 "Contact" address:"mailto:craig@whimsy.co.nz" align:#left
			hyperlink H_link2 "Home Page" address:"http://www.whimsy.co.nz" align:#left
			label lab3 "Thanks to all who contribute at" align:#left
			hyperlink H_link3 "Scriptspot" address:"http://www.scriptspot.com" align:#left
		)
	on BTN_ReduceKeys pressed do
		(
		
			disableSceneRedraw()

			CurrAnimRange = animationrange -- holds the current animation range value
			animationrange = interval SP_Range_STRT.value SP_Range_End.value -- sets the animationrange to user selected values
		
			newpoint = point size:0.001 -- Evades the need to have a special single selection case
			selectmore newpoint -- ditto
		
			for i in 1 to $.count do -- for-loop reduceKey start
				(
					reduceKeys $[i].controller SP_Threshold.value SP_Duration.value animationrange
				)--end for-loop reduceKey	
				
			if RB_KeyAtZero.state == 2 do
			(		
				for i in 1 to $.count do -- for-loop AddZeroKey start
				(
					addnewkey $[i].controller 0 -- just in case it runs away and deletes the key at frame 0
				)--end for-loop AddZeroKey
			)
			
			if RB_KeyAtEnd.state == 2 do
			(
				for i in 1 to $.count do -- for-loop AddEndFrameKey start
				(
					addnewkey $[i].controller SP_Range_End.value -- just to be tidy	
				)--end for-loop AddEndFrameKey
			)
			
				
			delete newpoint -- tidy up
		
			animationrange = CurrAnimRange --resets the animation range
		
		
			enableSceneRedraw()
		
		) -- end button

	) -- end rollout

	createDialog RLT_ReduceKeys width:200 height:350 --pos:[25, 25]
)