macroScript SMD_Batch_Exporter Category:"Tools" \

		ButtonText:"SMD batch export" \

		tooltip:"Export folder full of .max files to .smds"

(

Rollout SMDBatchExport ""

(	

fn Process_Folder Target_Folder Final_Dest_Folder =

	(Max_file_Array = getfiles (Target_Folder + "\\*.max")

	for Items in Max_File_Array do

		(

		loadmaxfile items

		Target_Root = GetFileNameFile items

		exportfile (Final_Dest_Folder + "\\" + Target_Root + ".smd") #noprompt

		)

	if Querybox ("Exit Max?") then quitmax()

	)

	group "Export All SMDs to:" (

	radiobuttons Mode "" labels:#("Same folder as Max files","Folder:") columns:1 default:1 offset:[-70,0]

	button Set_Dest_Folder "Set" across:2 offset:[190,-22]

	edittext Dest_Folder width:180 offset:[-80,-20] enabled:false 

	button Get_Folder "Select & Export Folder" 

	)

	on Mode changed state do

		case state of 

			(

			1: (Dest_Folder.enabled = false)

			2: (if Dest_Folder.text == "" then 

					(

					New_Dest = GetSavePath "Select destination folder for SMD files"

					if New_Dest != undefined then 

						(

						Dest_Folder.text = New_Dest

						Dest_Folder.enabled = true

						)

						else

						(

						Dest_Folder.enabled = false

						Mode.State = 1

						)

					)

				else

					(Dest_folder.enabled = true)

				)

			)

			

	on Set_Dest_Folder pressed do

		(

		New_Dest = GetSavePath "Select destination folder for SMD files"

		if New_Dest != undefined then 

			(

			Dest_Folder.text = New_Dest

			Dest_Folder.enabled = true

			Mode.state = 2

			)

			else

			(

			Dest_Folder.text = ""

			Mode.State = 1

			Dest_folder.enabled = false

			)

		)

		

	on Get_Folder pressed do

		(

		Target_Folder = GetSavePath ("Select Folder to process:")

		if Target_Folder != undefined do 

			(

			Final_Dest_folder = if Dest_Folder.enabled then Dest_folder.text else Target_folder

			Process_Folder Target_Folder Final_Dest_Folder)

		)



) --- end rollout



SMDXwindow = NewRolloutFloater "SMD Batch Exporter" 320 160

Addrollout SMDBatchExport SMDXwindow



) --- end macro
