Help with (simple?) script

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 and just can't see why this shouldn't work.

Comments

Comment viewing options

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

I have the same error with

I have the same error with your code.
But this works:

on btnDelete pressed do
		(
			case rdoLec2.state of
			(
				1: (delete $box*)
				2:
				(
					obj = objects as array
					for i = obj.count to 1 by -1 where (classOf obj[i] != box) do delete obj[i]	
				)
				3: (delete $objects)
			)				
		)

This also works fine:

obj = objects as array
for o in obj where (classOf o != box) do delete o	
jos's picture

for i in $objects do ( if

for i in $objects do
(
   if classOf i!=box then delete i
)
--returns OK
jfjohnny5's picture

And it does return OK if I

And it does return OK if I just enter that in the listener, but when part of the overall utility embedded in an event handler it fails. I can't figure out why.

Posted code below as you requested...

miauu's picture

This work for me: ( for o

This work for me:

(
	for o in objects do
		if classOf o != box do delete o
)
jfjohnny5's picture

I just tried exactly what you

I just tried exactly what you wrote and still no dice.

The only other info is that this is part of a Utility. So the user presses a button to make this bit of code run. I can't think of how that would change anything, but there it is.

I just keep getting:

>> MAXScript Rollout Handler Exception:
-- Unknown system exception <<

jos's picture

can you post your code

can you post your code please?

jfjohnny5's picture

Here's my code...

utility utLec2 "Lec 2 Demo"
(
	button btnRed "Red Box" width:70 offset:[-5,0] across:2
	button btnYellow "Yellow Sphere" width:70 offset:[5,0]
	radiobuttons rdoLec2 "Remove ..." labels:#("Boxes only", "Everything except Boxes", "All")
	button btnDelete "Delete Now"
 
	on btnRed pressed do
		box wirecolor:red position:[-20,0,0]
 
	on btnYellow pressed do
		sphere wirecolor:yellow position:[20,0,0]
 
	on btnDelete pressed do
	(
		if rdoLec2.state == 1 then
			delete $box*
		if rdoLec2.state == 2 then
			for i in $objects do
				if classOf i != box then 
					delete i
		if rdoLec2.state == 3 then
			delete $objects
	)
)

Comment viewing options

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