PDA

View Full Version : Batch process - open max files in folder, remove objects by name.


Michael Chen
12-12-2007, 01:23 AM
Hi Everyone,

I'm currently thinking about writing a script that does this...

1. Goes into a folder (which may contain many max files).
2. Opens a max file.
3. Removes all objects that have the name starting with "AB_". Even if it's hidden or frozen.
4. Save the file and close the file.
Repeat and open the next file until all max files within the folder have been processed.

Does anyone know of a similar open soure script like this. Just don't feel like reinventing the wheel if someone has already made it available :D

Thanks for reading. BTW I'm using Max8.

regards,
Mike

ypuech
12-12-2007, 08:46 AM
I think you can take a look at Paul Neale's "Batch It Max" : http://paulneale.com/scripts/batchItMax/batchItMax.htm

Zbuffer
12-12-2007, 11:45 AM
Hi,

Well seams easy enough ;)

(
-- change RootDir and pat to what you need
local RootDir=getdir #scene -- Base folder to search
local pat = "AB_*" -- pattern for name compare
local theFiles=getfiles (RootDir+"\\*.max (file:///*.max)") -- collect the max filenames in that folder
for File in theFiles do
(
loadMaxFile File useFileUnits:true quiet:true
--collect the objects who's name start with pat
DelObjects = for o in objects where (matchpattern o.name pattern:pat) collect o
format "\nScene: %\nObjects to delete: %\n" File DelObjects.count
for o in DelObjects do format "%\n" o.name
-- backwards loop to delete the objects
for i=DelObjects.count to 1 by -1 do delete DelObjects[i]
SaveMaxFile File
)
)

ypuech
12-12-2007, 01:56 PM
If you want to use "Batch It Max" developed by Paul Neale, you can perform the operation on each Max file processed by the script as coded by ZBuffer:

--collect the objects who's name start with pat
DelObjects = for o in objects where (matchpattern o.name pattern:pat) collect o
format "\nScene: %\nObjects to delete: %\n" File DelObjects.count
for o in DelObjects do format "%\n" o.name
-- backwards loop to delete the objects
for i=DelObjects.count to 1 by -1 do delete DelObjects[i]

Save this MAXScript code ms and add it to the batch scripts of the tool.

Michael Chen
12-12-2007, 09:33 PM
Hi ypuech and Zbuffer,

Thanks for the replies. Much appreciated.

I've actually started to code it myself. However seeing what others have done helps a lot :)


loadMaxFile File useFileUnits:true quiet:true

That's a neat code to overcome the missing material issue.

Also Paul's "Batch It Max" recursive feature could be quite useful.

PEN
12-12-2007, 09:51 PM
If you need any help with that tool just let me know. Been using it for years and it works great.

Michael Chen
12-13-2007, 10:32 PM
If you need any help with that tool just let me know. Been using it for years and it works great.

Hi Paul,

Thanks for sharing this great script.

I've had a few issues using the script, but not too serious. Not sure if it's to do with the script or what's in my file.

I'm batch processing a lot of files (around hundreds). It often stops around 20 ~ 30% of the way, and I also get this error...


Alert box saying...
==============
Title: MaxScript Rollout Handler Exception
Description: Unknown system exception


This is what appears in the MaxScript listener...
====================================
-- Error occurred in x loop; filename: C:\Program

Files\Autodesk\3dsMax8\stdplugs\stdscripts\PEN_batchItMax.ms; position: 11265
-- Frame:
-- file: undefined
-- path: undefined
-- x: 437
-- scriptsIn: undefined
-- called in process_bt.pressed(); filename: C:\Program

Files\Autodesk\3dsMax8\stdplugs\stdscripts\PEN_batchItMax.ms; position: 12502
-- Frame:
-- num: 6
-- scriptSel: 1
-- fileSel: 200
>> MAXScript Rollout Handler Exception: -- Unknown system exception <<


The line that gets highlighted in your code...
=================================
loadMaxFile maxFiles_mlb.items[x] useFileUnits:true quiet:true


When I get the error I restart Max again. Then start off where I got the error. Works fine for a while then I get the exception again at around 20 ~ 30%. Not sure why.

Just thought you might like to know :)

BTW I'm using Max8.

PEN
12-13-2007, 10:38 PM
Watch your ram and see if memory is a problem. I used that tool in Max 8 allot and didn't have issues with it.

Michael Chen
12-13-2007, 11:06 PM
Thanks for the quick reply.

I'll look into that.

PEN
12-14-2007, 12:20 PM
I don't know what your script is doing but put a gc() at the end of it to clear memory each pass.

CGTalk Moderation
12-14-2007, 12:20 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.