ScriptSpot

Forum topic · General Scripting

macroScript problems catergory: "unknown"

By gramx · 2011-01-05

Description

Hi

I have scripted a rollout interface, which is working within max when you run the script. I want to assign it to a custom menu so I need to convert it into a macroscript and put it in stdscripts. When I now load max I get the following error:-
>> MAXScript Auto-load Script Error -- Unknown system exception <<

After removing many lines of code I finally found the offending line.

The macroscript:-


macroScript MakeRig
	category:"Rigs"
(
	--destroy dialog if already open
	--if (::camRig != undefined ) do (destroyDialog camRig)
	if camRig != undefined  do destroyDialog camRig
--main rollout
	rollout camRig "Create V-Ray Camera Rig"
	(
		
		local bm1 = bitmap 100 100 color:red		
		local theName = "Camera01"
		
		group "Camera"
		(
			edittext prefix_txt "Name prefix: " fieldWidth:165 text: "Camera01"
		)
		group "Rig"
		(
			--imgtag b1 "imgtag" bitmap:bm1 pos:[20,68]
			button but_cancel "Cancel" pos:[200,210]
			on but_cancel pressed do 
			(
				destroyDialog camRig
			)
		)
	)
		createDialog camRig 260 240
)

If I remove the following lines:-
local bm1 = bitmap 100 100 color:red
Then I dont get any errors! Can anyone help?

edit: I have just worked out that if I move this line above the rollout then I dont get the error on loading max. I still dont know why you must do this. The other variables like local theName = "Camera01" work fine.

I have also been using the following line to destroy dialog if already open:-
if camRig != undefined do destroyDialog camRig
Again this works in a normal script but if I use it in a macroScript it does nothing! Looking at someone elses script I have found a line that does work:-
if (::camRig != undefined ) do (destroyDialog camRig)
What is the difference and what do the :: mean?

Thanks for any help!

Gram

Comments (2)

most wrong was with pressed event

Anubis · 2011-01-05

::camRig

is incorect variable cause used special characters, and this --

if camRig != undefined  do destroyDialog camRig

is correct at all, but read the notes...

macroScript MakeRig category:"Rigs"
(
	global camRig -- define the rollout as Global,
	-- to can be visible ouside of the macro script scope
	
	-- next test the type of your var 'camRig' cause it maybe defined but...
	-- hold something else, not rollout definition
	if classOf camRig == RolloutClass do destroyDialog camRig
--main rollout
	rollout camRig "Create V-Ray Camera Rig"
	(
		--// locals:
		local bm1 = bitmap 100 100 color:red		
		local theName = "Camera01"
		
		--// ui:
		group "Camera"
		(
			edittext prefix_txt "Name prefix: " fieldWidth:165 text: "Camera01"
		)
		group "Rig"
		(
			imgtag b1 "imgtag" bitmap:bm1 pos:[20,68]
			button but_cancel "Cancel" pos:[200,210]
			
		)
		-- Note: your 'on but_cancel pressed do' was inside group "Rig"
		-- this is wrong ;-)
		
		--// events:
		on but_cancel pressed do 
		(
			destroyDialog camRig
		)
	)
	createDialog camRig 260 240
)

gramx · 2011-01-05

Thanks Anubis,

Looks like I need to re-arange my code a bit more. I have got it working now but I still have events all over the place. I will reorganise it as sujjested.

Thanks again

Gram