reseting or closing script when file is reset or closed

Hi all
I've create a batch render script that is max file dependent (stores perminent varibles). So it stores information inputted by the user for example the project name and render location etc.

What I'm currently having difficulty with is that I would like the script to know when the user resets max or closes the file or opens a new file so that the script can be closed so that the information from the previous file isn't transferred to the new save.

Any help would be appreciated.

Phil

Comments

Comment viewing options

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

I'll give it another go at

I'll give it another go at describing what I'm after.

I've cut my script down just to illustrate what I am hoping to achieve.

macroScript MultiSubmit
	category:"NSC Creative"
	toolTip: "Multi-Submit"
	buttonText:"Multi-Submit"
	icon:#("standard",2)
 
(
		persistent global browserdirPer
		)
		if
		browserdirPer == undefined then browserdirPer = "not set"
 
		rollout MultiSubmitter "Quick Render, Beta V4.3" width:20 height:200
(	
	EditText ed_browserDir width:441 height:17 offset:[-13,3] align:#center text:(browserdirPer as string) -- test
 
	on ed_browserDir changed txt do (
		browserdirPer = ed_browserDir.text
	)
 
 
 
	--on User close, load, reset, (whatever the user can do to mean that the file is no longer open) do(	
	--Destroydialog MultiSubmitter -- close the dialog box
	--)
)
	createDialog MultiSubmitter width:510 height:340
addRollout MultiSubmitter nf
 

So in this example I've put the on command and --(whatever the user.... to illustrate what I want it to do.

In the full script what I would want is that when someone loaded another file it would close the dialogue so when it is opened again it contains the persistent globals that are saved in the loaded file. without it being closed it just continues to show the old persistant globals. Additionally when someone resets or goes for a new scene the dialouge is closed and the persistant globals are wiped.

Hope I've explained it a bit better

Anubis's picture

you can use callbacks fn

you can use callbacks

fn closeMultiSubmitter = (
	if classOf closeMultiSubmitter == RolloutClass do
		DestroyDialog closeMultiSubmitter
)
 
callbacks.removeScripts id:#fileClose
callbacks.addScript #filePreOpen "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreNew "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreReset "closeMultiSubmitter()" id:#fileClose

my recent MAXScripts RSS (archive here)

Philip Day's picture

I've tried implementing the

I've tried implementing the script but I seem to be getting an error message.

-- Error occurred in closeMultiSubmitter(); filename: Z:\96-RandD\001 Multi-Submit\Test Ground\very  simple.ms; position: 393; line: 15
--  Frame:
--   MultiSubmitter: undefined
--   called in anonymous codeblock
--  Frame:
>> MAXScript Callback script Exception: -- Type error: DestroyDialog requires RolloutClass, got: undefined <<

I've tried putting the script in different places but I still get the same message. Sometimes once the script has failed it then starts working the next time until I reload max.

Example of cutdown script. (note that the added script is probably in the wrong place but I seem to get the same message where ever I put it.

macroScript MultiSubmitTester
	category:"NSC CreativeTest"
	toolTip: "Multi-Submit"
	buttonText:"Multi-Submit"
	icon:#("standard",2)
 
(
		persistent global browserdirPer
		)
		if browserdirPer == undefined then browserdirPer = "not set"
 
		fn closeMultiSubmitter = (
			if classOf closeMultiSubmitter == RolloutClass do
				print rolloutclass
				DestroyDialog MultiSubmitter
		)
 
 
		rollout MultiSubmitter "Quick Render, Beta V4.3" width:20 height:200
(	
	EditText ed_browserDir width:441 height:17 offset:[-13,3] align:#center text:(browserdirPer as string) -- test
 
	on ed_browserDir changed txt do (
		browserdirPer = ed_browserDir.text
	)
 
 
 
 
)
	createDialog MultiSubmitter width:510 height:340
addRollout MultiSubmitter nf
 
callbacks.removeScripts id:#fileClose
callbacks.addScript #filePreOpen "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreNew "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreReset "closeMultiSubmitter()" id:#fileClose

Any ideas?

Anubis's picture

Seems you made some syntax

Seems you made some syntax mistake after editing the function. The brackets are important when you add more than one command to the same scope. Adding a new command "print rolloutclass" without brackets for the IF/DO cause the next command "DestroyDialog MultiSubmitter" to be runned out of the IF/DO scope (and without class checking), i.e.:

-- this...
if classOf closeMultiSubmitter == RolloutClass do
	print rolloutclass
	DestroyDialog MultiSubmitter
 
-- ...is readed by Max like this
if classOf closeMultiSubmitter == RolloutClass do
(
	print rolloutclass
)
DestroyDialog MultiSubmitter
 
-- you don't need this "print rolloutclass" at all
-- but if you wish to add it by some reason,
-- put both commands in the same scope
-- i.e. write the function like this:
fn closeMultiSubmitter = (
	if classOf closeMultiSubmitter == RolloutClass do (
		print rolloutclass
		DestroyDialog MultiSubmitter
	)
)

my recent MAXScripts RSS (archive here)

Philip Day's picture

Thanks for the reply. I had

Thanks for the reply. I had forgotten that I had put that in. It was my attempt to work out what was going on while I was getting the error and I had forgot to remove it.

However I have done as you suggested Code below and I don't get the error but it doesn't close the dialog box. however once I have run the script once I can remove the line if classOf closeMultiSubmitter == RolloutClass and it does close the box without error.

macroScript MultiSubmitTester
	category:"NSC CreativeTest"
	toolTip: "Multi-Submit"
	buttonText:"Multi-Submit"
	icon:#("standard",2)
 
(
		persistent global browserdirPer
		)
		if browserdirPer == undefined then browserdirPer = "not set"
 
	fn closeMultiSubmitter = (
		if classOf closeMultiSubmitter == RolloutClass do 			
			DestroyDialog MultiSubmitter		
	)
 
 
 
		rollout MultiSubmitter "Quick Render, Beta V4.3" width:20 height:200
(	
	EditText ed_browserDir width:441 height:17 offset:[-13,3] align:#center text:(browserdirPer as string) -- test
 
	on ed_browserDir changed txt do (
		browserdirPer = ed_browserDir.text
	)
 
)
	createDialog MultiSubmitter width:510 height:340
addRollout MultiSubmitter nf
 
 
callbacks.removeScripts id:#fileClose
callbacks.addScript #filePreOpen "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreNew "closeMultiSubmitter()" id:#fileClose
callbacks.addScript #systemPreReset "closeMultiSubmitter()" id:#fileClose

I feel like I'm almost there.

But not quite :)

Anubis's picture

Ah, yes, something

Ah, yes, something important... the rollouts inside MacroScripts are local. Declare it as global (global closeMultiSubmitter) at the beginning of the macros ;)

my recent MAXScripts RSS (archive here)

Philip Day's picture

Thank you for your advice. It

Thank you for your advice. It is now working as I want, or at least I think so. Just to post my conclusions for anyone else having problems or wanting to do something similar here is the process implemented into a simplified version of my script.

macroScript MultiSubmitTester
	category:"NSC CreativeTest"
	toolTip: "Multi-Submit"
	buttonText:"Multi-Submit"
	icon:#("standard",2)
 
(
		global closeMultiSubmitter
		persistent global browserdirPer
		)
 
		if browserdirPer == undefined then browserdirPer = "not set"
 
 
 
 
		rollout MultiSubmitter "Quick Render, Beta V4.3" width:20 height:200
(	
	EditText ed_browserDir width:441 height:17 offset:[-13,3] align:#center text:(browserdirPer as string) -- test
 
	on ed_browserDir changed txt do (
		browserdirPer = ed_browserDir.text
	)
 
	on MultiSubmitter open do (
 
			fn closeMultiSubmitter = (
		--if classOf closeMultiSubmitter == RolloutClass do 			
			DestroyDialog MultiSubmitter		
	)
 
	callbacks.removeScripts id:#fileClose
	callbacks.addScript #filePreOpen "closeMultiSubmitter()" id:#fileClose
	callbacks.addScript #systemPreNew "closeMultiSubmitter()" id:#fileClose
	callbacks.addScript #systemPreReset "closeMultiSubmitter()" id:#fileClose
 
)
)
	createDialog MultiSubmitter width:510 height:340
addRollout MultiSubmitter nf

It seems to work now :)

Thanks again

Phil

Philip Day's picture

Thank you, I'll give that a

Thank you, I'll give that a go :)

Graph's picture

more info or the code pls

more info or the code pls

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Comment viewing options

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