How to make a script “batch friendly”

Hello fellow members of scriptspot. I use BatchIT by Paul Neale for batch processing max files, I enjoy using it, and highly recommend it. I have a question, as it appears to be an entirely different beast to prepare or format scripts to be used in a batch process. My question, for the most part is this: How would one go about making a script that will search for a given object and then if not found continue the search for the next object, so on and so forth, and then finally delete any of the found objects. With my limited scripting abilities, The only scripts that I can make would be a known existent target, and delete it, otherwise the script will hit the wall and the batch process will fail.

Comments

Comment viewing options

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

.

What criteria will be used to search the objects - their names, their positions, etc?

If you want to find and delete all objects which name is "ObjecetToDelete" then you can use this:

delete (for o in objects where o.name == "ObjecetToDelete" collect o)

If you want to find and delete all objects which name is "ObjecetToDelete_001", "ObjecetToDelete_002", "ObjecetToDelete_002_A", etc then you can use this:

delete (for o in objects where matchPattern o.name pattern:"ObjecetToDelete*" collect o)

Matt_K_Man's picture

Continued

Thank you so much for helping me out with this, miauu, I’ll have to try the script later today. Thanks again. Would you happen to know how to rename objects in a scene by adding a prefix to any name such as bone would be renamed Z_bone. The reason I ask this is because otherwise I would need to go in manually into hundreds of files and use a standard rename utility and it takes forever. How come there aren’t more batch scripts and batch utilities out there? That would be great

miauu's picture

.

Renaming the selected objects:

-- if object's name is "ZZZ" it will be renamed to "ZZZ_bone"
for o in selection do o.name += "_bone"
 
-- if object's name is "ZZZ" it will be renamed to "bone_ZZZ"
for o in selection do o.name = "bone_" + o.name
 
-- if object's name is "ZZZ" it will be renamed to "XYZ"
for o in selection do o.name = "XYZ"

Renaming all objects in the scene

-- if object's name is "ZZZ" it will be renamed to "ZZZ_bone"
for o in objects do o.name += "_bone"
 
-- if object's name is "ZZZ" it will be renamed to "bone_ZZZ"
for o in objects do o.name = "bone_" + o.name
 
-- if object's name is "ZZZ" it will be renamed to "XYZ"
for o in objects do o.name = "XYZ"
Matt_K_Man's picture

New

Thank you so much, Miauu. Works like a charm!

Comment viewing options

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