Basic deleting objects script

Hi there,

I'm very new to maxscript and am trying to write some very basic tools to speed up some of my repetitive tasks.
Ultimately i'm hoping to create a few scripts but the first one i'd like to create is a basic 'deleting a load of objects' script.

Ive worked out how to delete a set list of objects, but the problem comes when one of those objects is not in the scene. So i created an if statement which would get rid of roughly the right stuff if exactly the right stuff isn't there e.g:

if(delete#($Sphere02, $Sphere03, $Sphere04, $Sphere05, $Sphere06, $Sphere01)==undefined)then
delete $sphere*

But this is just a rough workaround - what I really want is to delete everything from a predefined list if is in the scene.

Any help would be gratefully appreciated,
cheers, Sean.

Comments

Comment viewing options

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

for loops through the array

for loops through the array previously created
o is the var that holds the value of the current iteration
where is basically an if statement wich has to evaluate true or the iteration will be skipped

Raphael Steves

boudini's picture

Wow, thanks Anubis. That

Wow, thanks Anubis. That worked perfectly.

I'm glad this approach worked, as I had thought I need to collect the valid nodes somehow, and then delete. So at least i'm starting to get to grips with the basics of how scripting works (although I am finding it hard to break into).

I don't really understand the 'o' after isValidNode, but I need to read up of for/where as its still a bit hazy to me.

Thanks again.

boudini's picture

Thanks for your reply Marco -

Thanks for your reply Marco - I'll read up on how to do a try catch statement. Its really helpful just to be given a pointer in the right direction as i didn't know something like that even existed.

As for storing the objects - i'm just not sure. Ive just been using: delete#($all, $my, $various, $objects). But i would understand that this is not a good way, and i should be storing them in some sort of variable or array?

Some more detail on the script may be useful - it would be more of a cleaning utility, that would clear out a certain character from a scene. The objects of the character will always be the same name, but they might not all be in the scene as they have different costumes and accessories. But i would ultimately have one button for 'delete character X' that would get rid of that character and all the possible items they could be wearing. (rather than a button for every variation of what they could be wearing - which would require quite a few buttons).

Cheers.

Anubis's picture

Collecting to array

Collecting to array (variable) and verify or filter out object that not exist (using isValidNode) before call delete() function, can help. For example:

objs = #($all, $my, $variaus)
-- filter out non existing objects:
objs = for o in objs where isValidNode o collect o
-- now just delete 'em
delete objs

my recent MAXScripts RSS (archive here)

Marco Brunetta's picture

What method are you using to

What method are you using to store the items that need to be deleted?

And you could always use a TRY CATCH statement. It's pretty rough and inefficient, but if it's just a personal script it might do the trick.

Comment viewing options

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