Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Batch clean .max files script does not open files in subfolders

Batch clean .max files script does not open files in subfolders

Anonymous
Not applicable
1,105 Views
2 Replies
Message 1 of 3

Batch clean .max files script does not open files in subfolders

Anonymous
Not applicable

Hello everyone! Probably a very simple question, but one I can not figure out.

So, long story short, I have about a 1000+ .max files polluted with random Fire and Atmospheric effects, and littered with empty animation layers. This has turned out to be a bit of a performance hog, so I am trying to clean the files. Naturally, manually cleaning them will not do. So I tried writing this script, which seems to be working fine (even though it is truly painfully slow for some reason, but let's say I can live with that. If anyone can help with this too however, all the better).

 

My real problem is this however - The script only processes the .max files in the folder I select, but not in any subsequent subfolders. I have been banging my head on how to get this to work, and I have had no luck as of yet. Any help in this regard would be truly and greatly appreciated, since my library structure is is divided into many, many subfolders.

 

And here is the current script:

 

 

thePath = getSavePath()--get a path dialog to specify the path
if thePath != undefined do--if the user did not cancel
(
theFiles = getFiles (thePath+"\\*.max") --collect all max files in the dir.
for f in theFiles do-- go through all of them
(
loadMaxFile f missingExtFilesList:&val missingExtFilesAction:#logmsg quiet:true--load the next file

-----------------------------------------------------------
-- MAKE SOME SCRIPTED CHANGES TO THE SCENE HERE...


while numAtmospherics > 0 do deleteAtmospheric 1

while numEffects > 0 do deleteEffect 1

--while AnimLayerManager.getLayerCount() > 0 do AnimLayerManager.deleteLayer 1

c=AnimLayerManager.getLayerCount()
for i = 2 to c do AnimLayerManager.deleteLayer 2

IsolateSelection.ExitIsolateSelectionMode()


-----------------------------------------------------------

saveMaxFile f --save the file back to disk
)--end f loop
-- resetMaxFile #noPrompt --at the end, you can reset
)--end if

 

 

0 Likes
1,106 Views
2 Replies
Replies (2)
Message 2 of 3

denisT.MaxDoctor
Advisor
Advisor

this is an example code from the MXS help:

fn getFilesRecursive root pattern =
(
	dir_array = GetDirectories (root+"/*")
	for d in dir_array do
		join dir_array (GetDirectories (d+"/*"))
	my_files = #()
	for f in dir_array do
		join my_files (getFiles (f + pattern))
	my_files
)
--get all .ms files from the folder c:/temp
--and all its subfolders:
getFilesRecursive "c:/temp" "*.ms"
0 Likes
Message 3 of 3

Anonymous
Not applicable

I have been trying to implement this and even managed to do so, so the script now technically works. However, it is incredibly slow.

I think this has to do with

for i in 1 to numAtmospherics do deleteAtmospheric 1
	
for i in 1 to numEffects do deleteEffect 1

c=AnimLayerManager.getLayerCount()
for i = 2 to c do AnimLayerManager.deleteLayer 2

where it is continuously checking for the number of effects and deleting only one effect or animation layer. Is there a way to delete all instances at once, where one does not know how many there are?

 

0 Likes