try (closeRolloutFloater RolloutFloaterTemplate) catch()

SelectionObjects = #()

-- nouveau menu deroulant
rollout RolloutTemplate "Tools"

(
	button Button01 "Center Pivot"
	on Button01 pressed do
		
	(
		SelectionObjects = selection as array
		
		if SelectionObjects.count != 0 then
		(	
			for items in SelectionObjects do
			(		
			theHold.Begin()
			items.pivot = items.center
			theHold.Accept "Undo Center Pivot"
			)
		)
		else
		(
			messagebox "Nothing Selected" title: "Selection is Empty"
		)
	)
		
	button Button02 "Center Pivot Bottom"
	on Button02 pressed do
		
	(
		SelectionObjects = selection as array
		
		if SelectionObjects.count != 0 then
		(	
			for items in SelectionObjects do
			(		
			theHold.Begin()
			items.pivot = [items.center.x, items.center.y, items.min.z]
			theHold.Accept "Undo Center Pivot Bottom"
			)
		)
		else
		(
			messagebox "Nothing Selected" title: "Selection is Empty"
		)
	)

	
	button Button03 "Center Object to World"
	on Button03 pressed do
		
	(
		SelectionObjects = selection as array
		
		if SelectionObjects.count != 0 then
		(	
			for items in SelectionObjects do
			(		
			theHold.Begin()
			items.pos = [0, 0, 0]
			theHold.Accept "Undo Center Object"
			)
		)
		else
		(
			messagebox "Nothing Selected" title: "Selection is Empty"
		)	
	)
		
	button Button04 "Process Fbx Export UE4"
	on Button04 pressed do
	(
		SelectionObjects = selection as array --indispensable de la convertir en array, sinon genere des erreurs!
		
		if SelectionObjects.count != 0 then
			(			
				for i=1 to SelectionObjects.count do
					(
						theHold.Begin()
						select SelectionObjects[i]
						resetxform SelectionObjects[i]
						macros.run "Modifier Stack" "Convert_to_Poly"
						ObjectPosition = SelectionObjects[i].position
						ObjectName = SelectionObjects[i].name
						SelectionObjects[i].pos= [0,0,0]
						theHold.Accept "Undo Export Process"
						exportfile ObjectName #noprompt selectedOnly:true using:ExporterPlugin.Classes[9]
						-- export de l'objet
						
						SelectionObjects[i].position = ObjectPosition --retour a la position d'origine
						messagebox ( ObjectName + " exported in /export" ) title: "Exported !" beep: false
					)
			)
		else 
			(
			messagebox "Nothing Selected" title: "Selection is Empty"
			)
	)
	
	button Button05 "Process Fbx Export Unity"
	on Button05 pressed do
	(
		SelectionObjects = selection as array --indispensable de la convertir en array, sinon genere des erreurs!
		if SelectionObjects.count != 0 then
			(			
				for i=1 to SelectionObjects.count do
					(
						theHold.Begin()
						CurrentMatrix = SelectionObjects[i].transform -- copie la matrice de transformation
						preRotate CurrentMatrix (eulertoquat (eulerAngles 90 0 0)) -- execute une pre-rotation sur la variable
						select SelectionObjects[i]
						SelectionObjects[i].transform = CurrentMatrix -- remplace la matrice actuelle par celle de la pre-rotation
						
						resetxform SelectionObjects[i]
						macros.run "Modifier Stack" "Convert_to_Poly"
						ObjectPosition = SelectionObjects[i].position
						ObjectName = SelectionObjects[i].name
						SelectionObjects[i].pos= [0,0,0]
						
						exportfile ObjectName #noprompt selectedOnly:true using:ExporterPlugin.Classes[9]
						-- export de l'objet
						-- retour a l'etat avant l'export
						preRotate CurrentMatrix (eulertoquat (eulerAngles -180 0 0))
						SelectionObjects[i].transform = CurrentMatrix
						SelectionObjects[i].position = ObjectPosition --retour a la position d'origin
						resetxform SelectionObjects[i]
						maxOps.CollapseNodeTo $ 1 true
						theHold.Accept "Undo Export Unity Process"
						messagebox ( ObjectName + " exported in /export" ) title: "Exported !" beep: false
					)
			)
		else 
			(
			messagebox "Nothing Selected" title: "Selection is Empty"
			)
	)
	
	button Button06 "Open Export Folder"
	on Button06 pressed do
		(
			PathExports = symbolicPaths.getPathValue "$exports"
			PatchExportsString = PathExports as string
			print PatchExportsString
			 shelllaunch  ( PatchExportsString + "") ""
		)
)
	
RolloutFloaterTemplate = newrolloutfloater "Tools" 220 195
addrollout RolloutTemplate RolloutFloaterTemplate