ScriptSpot

Forum topic · General Scripting

Could use some help :) <<Unknown system exception>>

By br0t · 2009-11-05

Description

Heyho!
i am currently messing around with max script a bit, trying to understand it and learn the commands, so i'm really new to this. For training i wrote this small script:

macroScript checkSelCount category:"Custom"
(
rollout checkSelCount "checkSelCount" width:132 height:63
(
edittext edt " " pos:[4,5] width:116 height:22
button btn "Update selection" pos:[3,33] width:122 height:23
)--end rollout

fn check_sel_count = (
if selection.count == 0 then
checkSelCount.edt.text = "Nothing selected" else
if selection.count > 1 then
checkSelCount.edt.text = "Multiple selected" else
checkSelCount.edt.text = "''" + $.name as String + "''" + " selected"
)--end function

on btn pressed do
(
check_sel_count()
)--end on

createDialog checkSelCount 132 63
checkSelCount.edt.readOnly = true
check_sel_Count()

)--end macroScript

It should simply print out in the edittext-field if nothing, one or multiple objects are selected (on start or when i hit the update button. I already had this working, but after i restarted max, i got lots of errors with undefined properties and after changing the order of some things, i now always get a an "unknown system exception".
I guess it's really simple to solve, but i'm stuck. Any ideas? And is there a better way to check if anything has been selected? And why do i sometimes get a Number in the Listener after evaluating my script, instead of "OK"?

Screenshot: http://s5.directupload.net/file/d/1969/o5wbx2l5_jpg.htm

Greetings :)

Comments (4)

Anubis · 2009-11-06

I am glad that I helped you. I forgot to add the "ro_" in the function as well :) and yes, in some cases the same names of macros and rollout will bring "unknown system exception".

And one hint about ";" symbol -- its end-of-line but needed only in case where you want to write 2 commands in 1 line, for example:

b = box()
b.width = 33
-- this is a 2 separate commands and can be writen on 1 line:
b = box() ; b.width = 33
-- but in this case:
if x > y then
      x
  else
      y
-- you can write it on 1 line:
if x > y then x else y -- the same as above

br0t · 2009-11-06

Ah...to tell the truth don't remember why I put those " ; " there. I did a little ActionScript some years ago, guess i mixed it up in that moment :P Anyway, thanks for the advice.

br0t · 2009-11-06

Great :) I did not know you have to place button events in the rollout. Will I run into problems when my rollout does have the same name as my macroscript?
I added the "ro_" in the function as well, and now it works, thanks alot Anubis :) !
Greetings

Just for testing out how you did that formatted code:


fn check_sel_count = (;
			if selection.count == 0 then;
				ro_checkSelCount.edt.text = "Nothing selected"
			else;
				if selection.count > 1 then;
					ro_checkSelCount.edt.text = "Multiple selected"
				else;
					ro_checkSelCount.edt.text = "''" + $.name as String + "''" + " selected";
		)--end function;

Anubis · 2009-11-06

Your button event (on pressed) is out of rollout.

macroScript checkSelCount category:"Custom"
(
	rollout ro_checkSelCount "checkSelCount"
	(
		
		fn check_sel_count = (
			if selection.count == 0 then
				checkSelCount.edt.text = "Nothing selected"
			else
				if selection.count > 1 then
					checkSelCount.edt.text = "Multiple selected"
				else
					checkSelCount.edt.text = "''" + $.name as String + "''" + " selected"
		)--end function

		edittext edt " " pos:[4,5] width:116 height:22
		button btn "Update selection" pos:[3,33] width:122 height:23

		on btn pressed do check_sel_count()
		
		on ro_checkSelCount open do 
		(
			edt.readOnly = true
			check_sel_Count()
		)
		
	)--end rollout
	
	createDialog ro_checkSelCount 132 63

)--end macroScript

Also I renamed rollout to ro_checkSelCount to not match the macros name.