Browse folder

Hey ! How are you ? :)

Look I've this :

files = getFiles "C:\Users\seven\Documents\3dsmax\FBX\*.max"

I want to create a dialog to looking for the directory I want.

for exemple

My_file => looking for my repertory in a dialog
files = getFiles My_file

How can I do this ?

Thanks for your help

Comments

Comment viewing options

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

The problem is that variable

The problem is that variable allFIles that holds all .max files from the selected folder is not "visible" when you press the btn_export. To fix this:

------------ DECLARATION DES VARIABLES ----------------------
			exportfolderASE = maxfilepath + "ASE\\"
			exportfolderGR2 = maxfilepath + "GR2\\"
			exportfolder3DS = maxfilepath + "3DS\\"
			exportfolder3DSMAX = maxfilepath + "3DSMAX\\"
 
				 -- 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)
				if doesFileExist exportfolder3DSMAX  == false do (makedir exportfolder3DSMAX)
-- 				
	--------------------- DEBUT ALGORITHME -------------------------
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "Lunastra Building Compiler • • •"
(
		local allFiles = #()
 
		button btn_import "Selection du dossier" align:"center"
		button btn_export "Exporter" align:"center"
		checkbox cbxExportOptions pos:[5,10] tooltip:"Display export dialog"
		label lblExportOptions "Export options" pos:[30,10]
 
		on btn_import pressed do
		(
			dir = getSavePath caption:"Select Folder" initialDir:#images
				 if dir != undefined do
				 (
					allFiles = getFiles (dir + "\\*.max")
					print allFiles
				  )
		)
 
		on btn_export pressed do
		(
			theClasses = exporterPlugin.classes
 
				for f in allFiles do
				(
					loadMAXFile f;
					max select all --select all objects
				(
					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
								)
							)
						)
					)
				)
					$.name = "Model"
					$selection.material = meditMaterials[1] --assign standard material
					$selection.wirecolor = black -- assign black color of wireframe
					viewport.SetRenderLevel #smoothhighlights
					(
					exportFile (exportfolderASE + (getFilenameFile maxFileName)+ ".ase") #noPrompt
					)
						-----------------------EXPORT GR2 + 3DS -----------------------
					(
					scale $Model [88,88,88]
					actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
					saveMAXFile (exportfolder3DSMAX+ (getFilenameFile maxFileName)+ ".max")
					exportFile (exportfolder3DS +(getFilenameFile maxFileName)+ ".3ds") #noPrompt using:exporterPlugin.classes[1]
					exportFile (exportfolderGR2 +(getFilenameFile maxFileName)+ ".gr2")
					)
				)
		)
)
Kasimashi's picture

Works perfect

Thanks !!!! it work perfect !

but what mean ?

local allFiles = #()
miauu's picture

allFIles is variable.It can

allFIles is variable.It can be a number(integer or float), a string, name,bitarray,array,etc.
local means tha this variable is visible only for the script and when you close the rollout the variable is deleted fromthe memory.

getFiles returns all files in the given directory as array, so
with:

local allFiles = #()

i define the allFiles to an array
In maxscript this
#()
means array and can contains almost whateveryou want.
Tthis
#{}
means bitarray().
Check the maxscript help file formore detailed explenations:
- Scope of variables
- array
- bitarray

When you define a variable in the
on btn_ pressed do
(

)
this variable can't be accessed in another event handle, so if you want to access a variable everywaher in the rollout you have to define it as local before any event handles or as a global(check Scope of variables in the maxscript helpfile).

miauu's picture

Idon't have max right now(I

Idon't have max right now(I am at work) but:

try(destroyDialog rol_Browse)catch()
rollout rol_Browse "Browse"
(
   button btn_browse "Browse"
 
   on btn_browse pressed do
   (
     dir = getSavePath caption:"Select Folder" initialDir:#images
     if dir != undefined do
     (
        allFiles = getFiles (dir + "\\*.max")
        print allFiles
      )
   )
)
createDialog rol_Browse
Kasimashi's picture

Thx

Thanks you but I can't find what is false in my script with your browse dialog :s

------------ DECLARATION DES VARIABLES ----------------------
			exportfolderASE = maxfilepath + "ASE\\"
			exportfolderGR2 = maxfilepath + "GR2\\"
			exportfolder3DS = maxfilepath + "3DS\\"
			exportfolder3DSMAX = maxfilepath + "3DSMAX\\"
 
				 -- 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)
				if doesFileExist exportfolder3DSMAX  == false do (makedir exportfolder3DSMAX)
-- 				
	--------------------- DEBUT ALGORITHME -------------------------
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "Lunastra Building Compiler • • •"
(
		button btn_import "Selection du dossier" align:"center"
		button btn_export "Exporter" align:"center"
		checkbox cbxExportOptions pos:[5,10] tooltip:"Display export dialog"
		label lblExportOptions "Export options" pos:[30,10]
 
		on btn_import pressed do
		(
			dir = getSavePath caption:"Select Folder" initialDir:#images
				 if dir != undefined do
				 (
					allFiles = getFiles (dir + "\\*.max")
					print allFiles
				  )
		)
 
		on btn_export pressed do
		(
			theClasses = exporterPlugin.classes
 
				for f in allFiles do
				(
					loadMAXFile f;
					max select all --select all objects
				(
					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
								)
							)
						)
					)
				)
					$.name = "Model"
					$selection.material = meditMaterials[1] --assign standard material
					$selection.wirecolor = black -- assign black color of wireframe
					viewport.SetRenderLevel #smoothhighlights
					(
					exportFile (exportfolderASE + (getFilenameFile maxFileName)+ ".ase") #noPrompt
					)
						-----------------------EXPORT GR2 + 3DS -----------------------
					(
					scale $Model [88,88,88]
					actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
					saveMAXFile (exportfolder3DSMAX+ (getFilenameFile maxFileName)+ ".max")
					exportFile (exportfolder3DS +(getFilenameFile maxFileName)+ ".3ds") #noPrompt using:exporterPlugin.classes[1]
					exportFile (exportfolderGR2 +(getFilenameFile maxFileName)+ ".gr2")
					)
				)
		)
)
createDialog bgaRoll 350 500 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Comment viewing options

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