Check my algorithm error ?

Hey !

I've made a algoritm but someone can say me if I've some error In my algorithm
And say me if it's possible to export first : the standart Building and after the Destroy building ... thanks for your help !

---------------- DECLARATION DES VARIABLES ----------------------
			exportfolderASE = maxfilepath + "ASE\\"
			exportfolderGR2 = maxfilepath + "GR2\\"
			exportfolder3DS = maxfilepath + "3DS\\"
 
				 -- CREATION DES REPERTOIRES S'IL N'EXISTE PAS -----
				if doesFileExist exportfolderASE  == false do (makedir exportfolderASE)
				if doesFileExist exportfolderGR2  == false do (makedir exportfolderGR2)
				if doesFileExist exportfolder3DS  == false do (makedir exportfolder3DS)
 
	--------------------- DEBUT ALGORITHME -------------------------			
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "Lunastra Building Compiler • • •"
(
	label Help1 "Standard ou détruit ?" align:#center
	button btn_delchilds "Standard" align:#center width:100 height:20 
	button btn_delparents "Détruit" align:#center width:100 height:20
	label Help2 "Reset Xform" align:#center
	button btn_xform "Reset Xform" align:#center width:100 height:20
	label Help3 "Mettez votre modèle droit en vous aidant" align:#center
	label Help4 "du repère et de l'outil rotation et cliquez sur Reset Xform" align:#center
	label Help5 "En cas de modification du Reset Xform Merci de relancer l'algorithme" align:#center
	label Help6 "Copyright by Kasimashi tout droit réservé 2013-2014 ©" align:#center
 
 
 
	on btn_delchilds pressed do
	(
		delete (for o in objects where matchPattern o.name pattern:("*2_*") collect o)
 
			----------------SELECT ALL -----------
			Select $*
			-------------- ATTACH ALL MESH 	--------------
				(
					mtl = #() ; tmp = #() ; fin = #()
					sel = selection as array
					if sel.count == 0 then -- check selection
						messageBox "Erreur lors de l'execution du script s'il vous plait contactez Kasimashi"
					else
					(	-- filter selection
						sel = for i in sel where classOf i == Editable_mesh \
							and i.material != undefined collect i
						if sel.count == 0 then
							messageBox "Aucun Mesh dans la séléction !!! " title:"Attacher les Mesh"
						else
						(
							for i in sel do
								appendIfUnique mtl i.material
							for m in mtl do
							(
								tmp = for i in sel where i.material == m collect i
								append fin tmp
							)
							undo on
							(
								for i in fin do
								(
									trg = i[1]
									deleteItem i 1
									for j in i do
										meshop.attach trg j attachMat:#IDToMat condenseMat:true
								)
							)
						)
					)
				)
			------------------ RENAME MODEL ------------
				$.name = "Model"
				select $Model
			-------------------- WORKING PIVOT + PIVOT ==> RESET XFORM-------------------------
				----$ .pivot = [0,0,0]
				----workingpivot = [0,0,0]
				--resetxform $;
			---------------------- PLACE 0;0;0 -----------------
				$.pos = [0,0,0]
			------------------- SCALE 1/88 FOR FREEWORLD LUNASTRA------------------------
				exportFile (exportfolderASE + (getFilenameFile maxFileName)+".ase") #noPrompt
			-----------------------EXPORT GR2 + 3DS -----------------------
				(
					scale $Model [88,88,88]
				)
				exportFile (exportfolder3DS +(getFilenameFile maxFileName)+".3ds") #noPrompt using:exporterPlugin.classes[1]
				exportFile (exportfolderGR2 +(getFilenameFile maxFileName)+".gr2")
			-------------------------(RECTIFICATION)--------------------
				(
					scale $Model [0.0113636363636364,0.0113636363636364,0.0113636363636364]
					actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
				)
	)
 
	on btn_delparents pressed do
	(
		delete (for o in objects where matchPattern o.name pattern:("*2_*") and o.parent != undefined collect o.parent)
			----------------SELECT ALL -----------
			Select $*
			-------------- ATTACH ALL MESH 	--------------
				(
					mtl = #() ; tmp = #() ; fin = #()
					sel = selection as array
					if sel.count == 0 then -- check selection
						messageBox "Erreur lors de l'execution du script s'il vous plait contactez Kasimashi"
					else
					(	-- filter selection
						sel = for i in sel where classOf i == Editable_mesh \
							and i.material != undefined collect i
						if sel.count == 0 then
							messageBox "Aucun Mesh dans la séléction !!! " title:"Attacher les Mesh"
						else
						(
							for i in sel do
								appendIfUnique mtl i.material
							for m in mtl do
							(
								tmp = for i in sel where i.material == m collect i
								append fin tmp
							)
							undo on
							(
								for i in fin do
								(
									trg = i[1]
									deleteItem i 1
									for j in i do
										meshop.attach trg j attachMat:#IDToMat condenseMat:true
								)
							)
						)
					)
				)
			------------------ RENAME MODEL ------------
				$.name = "Model"
				select $Model
			-------------------- WORKING PIVOT + PIVOT ==> RESET XFORM-------------------------
				----$ .pivot = [0,0,0]
				----workingpivot = [0,0,0]
				---resetxform $;
			---------------------- PLACE 0;0;0 -----------------
				$.pos = [0,0,0]
			------------------- SCALE 1/88 FOR FREEWORLD LUNASTRA------------------------
				exportFile (exportfolderASE + (getFilenameFile maxFileName)+"_destroyed"+".ase") #noPrompt
			-----------------------EXPORT GR2 + 3DS -----------------------
				(
					scale $Model [88,88,88]
				)
				exportFile (exportfolder3DS +(getFilenameFile maxFileName)+"_destroyed"+".3ds") #noPrompt using:exporterPlugin.classes[1]
				exportFile (exportfolderGR2 +(getFilenameFile maxFileName)+"_destroyed"+".gr2")
			-------------------------(RECTIFICATION)--------------------
				(
					scale $Model [0.0113636363636364,0.0113636363636364,0.0113636363636364]
					actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
				)
	)
	---------------------- FIN ALGORITHME ---------------------------
	on btn_xform pressed do
	(
		for theNode in selection do if (isValidNode(theNode)) do ResetXForm theNode
	)
)
createDialog bgaRoll 350 195 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Comments

Comment viewing options

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

Use MAX UNDO

For example:

scale $Model [88,88,88]
exportModelFN
 
max undo -- the objects is unscaled
-- scale again to desired value
scale $Model [0.88,0.88,0.88]
exportModelFN
miauu's picture

You can optimize the script.

 
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "Lunastra Building Compiler • • •"
(
	---------------- DECLARATION DES VARIABLES ----------------------
	local exportfolderASE = maxfilepath + "ASE\\"
	local exportfolderGR2 = maxfilepath + "GR2\\"
	local exportfolder3DS = maxfilepath + "3DS\\"
	--------------------- DEBUT ALGORITHME -------------------------
 
	label Help1 "Standard ou détruit ?" align:#center
	button btn_delchilds "Standard" align:#center width:100 height:20 
	button btn_delparents "Détruit" align:#center width:100 height:20
	label Help2 "Reset Xform" align:#center
	button btn_xform "Reset Xform" align:#center width:100 height:20
	label Help3 "Mettez votre modèle droit en vous aidant" align:#center
	label Help4 "du repère et de l'outil rotation et cliquez sur Reset Xform" align:#center
	label Help5 "En cas de modification du Reset Xform Merci de relancer l'algorithme" align:#center
	label Help6 "Copyright by Kasimashi tout droit réservé 2013-2014 ©" align:#center
 
	function PutYourNameOfTheFN suff =
	(
		----------------SELECT ALL -----------
			Select $*
			--	instead of select $* you can use
			--	max select all 
			-------------- ATTACH ALL MESH 	--------------
				(
					mtl = #() ; tmp = #() ; fin = #()
					sel = selection as array
					if sel.count == 0 then -- check selection
						messageBox "Erreur lors de l'execution du script s'il vous plait contactez Kasimashi"
					else
					(	-- filter selection
						sel = for i in sel where classOf i == Editable_mesh \
							and i.material != undefined collect i
						if sel.count == 0 then
							messageBox "Aucun Mesh dans la séléction !!! " title:"Attacher les Mesh"
						else
						(
							for i in sel do
								appendIfUnique mtl i.material
							for m in mtl do
							(
								tmp = for i in sel where i.material == m collect i
								append fin tmp
							)
							undo on
							(
								for i in fin do
								(
									trg = i[1]
									deleteItem i 1
									for j in i do
										meshop.attach trg j attachMat:#IDToMat condenseMat:true
								)
							)
						)
					)
				)
			------------------ RENAME MODEL ------------
				$.name = "Model"
				select $Model
			-------------------- WORKING PIVOT + PIVOT ==> RESET XFORM-------------------------
				----$ .pivot = [0,0,0]
				----workingpivot = [0,0,0]
				--resetxform $;
			---------------------- PLACE 0;0;0 -----------------
				$.pos = [0,0,0]
			------------------- SCALE 1/88 FOR FREEWORLD LUNASTRA------------------------
				exportFile (exportfolderASE + (getFilenameFile maxFileName)+ suff + ".aes") #noPrompt
			-----------------------EXPORT GR2 + 3DS -----------------------
				(
					scale $Model [88,88,88]
				)
 
				exportFile (exportfolder3DS +(getFilenameFile maxFileName)+ suff + ".3ds") #noPrompt using:exporterPlugin.classes[1]
				exportFile (exportfolderGR2 +(getFilenameFile maxFileName)+ suff + ".gr2")
			-------------------------(RECTIFICATION)--------------------
				(
					scale $Model [0.0113636363636364,0.0113636363636364,0.0113636363636364]
					actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
				)
	)
 
	on btn_delchilds pressed do
	(
		delete (for o in objects where matchPattern o.name pattern:("*2_*") collect o)
 
		PutYourNameOfTheFN ""	
	)
 
	on btn_delparents pressed do
	(
		delete (for o in objects where matchPattern o.name pattern:("*2_*") and o.parent != undefined collect o.parent)
 
		PutYourNameOfTheFN "_destroyed"	
	)
	---------------------- FIN ALGORITHME ---------------------------
	on btn_xform pressed do
	(
		for theNode in selection do if (isValidNode(theNode)) do ResetXForm theNode
	)
 
	on open bgaRoll do
	(
		-- CREATION DES REPERTOIRES S'IL N'EXISTE PAS -----
		if doesFileExist exportfolderASE  == false do (makedir exportfolderASE)
		if doesFileExist exportfolderGR2  == false do (makedir exportfolderGR2)
		if doesFileExist exportfolder3DS  == false do (makedir exportfolder3DS)
	)
)
createDialog bgaRoll 350 195 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

The exportfolderASE, exportfolderGR2, exportfolder3DS are global in your script. Did you need they to be global? I put them in the rollout, so they are local. Check the Scope of variables in the maxxcript help file for the difference between global and local variables. One of the major rules is to use global variables only when you need them, otherwise use local variables.

Kasimashi's picture

:) Thanks for your help !

:) Thanks for your help !
but how can I scale $Model [88,88,88] and undo to come back with original scale because scale $Model [0.0113636363636364,0.0113636363636364,0.0113636363636364] is not a excact value I want 1/88 scale.

How can I do this ?

Thanks

Kasimashi

Comment viewing options

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