Notifications
Clear all

[Closed] Open nextfile from above folder with script

i have a folder containing of 10 max files, naming different names, ,

but i would like to have a script like, whenever i run the script it should open the next file, and next file for every time i run script, is this possible??

10 Replies

this one is a little more complex.
Instead of giving you a full script this time i will give you the steps to make the script yourself.

First you have to get the current “maxfilename” and “maxfilepath”.
By using the above commands you will get them.

then you can get an array containing all the max files contained in the current maxfilepath.
like this :

files = getFiles (maxfilepath+"*.max")

Now you have an array with all the files contained in the folder, and the name of your current max file.
you have to find the index of your currentmaxfile to know where you are in the array.
you can do this with finditem function. wich takes as argument, the array and the element to seek for.

CurrentFileIndex = finditem files (maxfilepath+maxfilename)

this will return an index, thus positionning your file into the array.

Now if you want to open the next file in the array :


 LoadMaxFile files[CurrentFileIndex+1]

files is the array, and the text in between the brackets give the index to select from that array.
This will return a max file to load into max.

You have to be careful with the index in an array because if you get the latest object in the array and increase by 1, it will get out of range. instead you should select the first element of the array. (this would make to loop into the array)

I hope this helps;)
Good luck

with this code i can come to get array of folders and path,
RootFolder = “C:\ est\”
folders = getDirectories(RootFolder+”*”)

but i am not getting is to array the list of max files in the respective folder and load each max file with next to next file…

say like i have folder named A and inside it contains named work.max
and now how can i load it, and next after load, if i again run this script, it should load next 3dsmax file from the folder named A…

like wise… any replies??

but i am not getting is to array the list of max files in the respective folder and load each max file with next to next file…

  you get an array of files with :
files = getFiles (maxfilepath+"*.max")
 when you enter maxfilepath in the listener you get the path of the current max file that is opened in 3dsmax.

In my previous message, i explained how to increment into the array and how to load the corresponding maxfile…

If i have some time, i could make the script. but i am kinda busy now.

this script i tried like getting files from a single folder,

its opening a pair of files only, its not going for third file, why,

i feel i have to make something like making an increment on the loadmax files array selection of files in that folder…(:sad:sorry for troubling you, i am a new beginner with scripting:sad:)

if files.count>1 then (
files = getFiles (maxfilepath+”*.max”)
loadmaxfile files[1]
CurrentFileIndex = finditem files (maxfilepath+maxfilename)
LoadMaxFile files[CurrentFileIndex+1]
)

i tried something like this.

for i = 1 to 3 do
(
files = getFiles (maxfilepath+”*.max”)
loadmaxfile files[i]
CurrentFileIndex = finditem files (maxfilepath+maxfilename)
LoadMaxFile files[CurrentFileIndex+i]

)

but no success. it opens only 2files… one after other

for i = 0 to 3 do
(
files = getFiles (maxfilepath+”*.max”)
loadmaxfile files[i+1]
CurrentFileIndex = finditem files (maxfilepath+maxfilename)
LoadMaxFile files[CurrentFileIndex+i]

 )

finally this one worked… for me… making an increment in the array file list

but when it comes to two folder containing files, like root folder c: est\ how to access and increment … like incrementing the maxpath array

Here is your script,
Just open a max file and you will be able to navigate between all maxfiles that are in the same folder.

(
    	--
    	-- Load the next or the previous Max File that is in the current max file folder.
    	--
    	
    	fn LoadNextMaxFile increment = (
    		files = getFiles (maxfilepath+"*.max")
    		currentFileIndex = finditem files (maxfilepath+maxfilename)
    		newFileIndex = currentFileIndex + increment
    		-- Prevent from going outside the array range.
    		if newFileIndex  > files.count then newFileIndex=1
    		if newFileIndex  < 1 then newFileIndex=files.count	
    		checkForSave()
    		LoadMaxFile files[newFileIndex]	
    	)
    	
    	--- USER INTERFACE ---
    	global LoadNextmaxFile_UI
    	try (destroydialog LoadNextmaxFile_UI) catch()
    	rollout LoadNextmaxFile_UI "Load Max File" (
    			button btn_previousFile "<< Previous" width:80 pos:[10,10]
    			button btn_nextFile "Next >>" width:80 pos:[100,10]
    			on btn_previousFile pressed do LoadNextMaxFile (-1)
    			on btn_nextFile pressed do LoadNextMaxFile (1)
    	)
    	createDialog LoadNextmaxFile_UI width:190 height:40
    	
    )

but how to get if i have files, in two different folders… like.

c: est\FolderA
c: est\FolderB
c: est\FolderC
and so on. …

this one is more complicated,

here is the script, it uses a recursive function that search for all the subfolders contained in the rootfolder.
Then it makes an array of all the files included in thes folders.
Finally you can go next or previous withint that array to open all the max files one after another.

here is the script :


  (
  	--
  	-- Load the next or the previous Max File that are in the RootFolder and its subfolders.
  	--
  	rootFolder="C:\\YourRootFolder\\"
  	
  	-- get recursively all the folders that are in RootFolder.
  	fn getDirectoriesRecursive folder arr =
  	(
  		dir = getDirectories (folder+"*")
  		for d in dir do (
  			append arr d
  			getDirectoriesRecursive d arr
  		)
  		return arr		
  	)
  	directories = getDirectoriesRecursive (rootFolder) #()
  	
  	files=#()
  	for d in directories do join files (getFiles (d+"*.max"))
  	
  	fn LoadNextMaxFile increment = (
  		currentFileIndex = finditem files (maxfilepath+maxfilename)
  		newFileIndex = currentFileIndex + increment
  		-- Prevent from going outside the array range.
  		if newFileIndex  > files.count then newFileIndex=1
  		if newFileIndex  < 1 then newFileIndex=files.count	
  		checkForSave()
  		LoadMaxFile files[newFileIndex]	
  	)
  	
  	--- USER INTERFACE ---
  	global LoadNextmaxFile_UI
  	try (destroydialog LoadNextmaxFile_UI) catch()
  	rollout LoadNextmaxFile_UI "Load Max File" (
  			button btn_previousFile "<< Previous" width:80 pos:[10,10]
  			button btn_nextFile "Next >>" width:80 pos:[100,10]
  			on btn_previousFile pressed do LoadNextMaxFile (-1)
  			on btn_nextFile pressed do LoadNextMaxFile (1)
  	)
  	createDialog LoadNextmaxFile_UI width:190 height:40
  	
  )
Page 1 / 2