ScriptSpot

Forum topic · General Scripting

Help with (simple?) script

By jfjohnny5 · 2012-04-12

Description

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 (7)

miauu · 2012-04-12

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	

for i in $objects do ( if

jos · 2012-04-12


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

jfjohnny5 · 2012-04-12

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...

This work for me: ( for o

miauu · 2012-04-12

This work for me:


(
	for o in objects do
		if classOf o != box do delete o
)

jfjohnny5 · 2012-04-12

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 · 2012-04-12

can you post your code please?

Here's my code...

jfjohnny5 · 2012-04-12


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
	)
)