PDA

View Full Version : Help with (simple?) script


jfjohnny5
04-12-2012, 03:20 PM
I'm a student that is just stumped by what seems a simple assignment. I simply need to write a script that will parse a given scene and delete anything that is NOT a box. I can accurately determine if something isn't a box with:

for i in $objects do
if classOf i!=box then

but as soon as I try to delete those objects by using:

delete i

I get a Unknown Exception Error. I have tried the help files for delete. I have also tried placing the objects in an array, iterating through the array and then deleting. I just can't see why this shouldn't work. Help please...

MattRennie
04-13-2012, 10:14 AM
give this a try

for i in objects do
(
if classof i != Box do
(
delete i
)
)

kogen
04-13-2012, 11:19 AM
When you use an array and you want to delete specific array items or nodes by using an index you haveto make sure running this array from the end to the start like:

for lvi = Arr.count to 1 by -1 do ( deleteitem Arr lvi)

I know this is not the exact answer to your question but this should work. If you do it the other way round you're changing the array size. Maybe that is what also hapens in your current case.

miauu
04-13-2012, 11:38 AM
@jfjohnny5 (http://forums.cgsociety.org/member.php?u=492867), check the scriptspot thread.

jfjohnny5
04-13-2012, 02:45 PM
Thanks! I finally got it.

CGTalk Moderation
04-13-2012, 02:45 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.