Check Gamma on/off on new scene load

Hello! I have a little script that checks Gamma on/off on script open:

on MyRollout open do
(
if IDisplayGamma.colorCorrectionMode == #gamma then
(
EnbGamma.checked = true

)
else
(
EnbGamma.checked = false
)
)

but how to do the same check on new scene load?

regards

Comments

Comment viewing options

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

.

Open maxscript reference file, search for General Event Callback Mechanism, then go File Notifications: and choose the callbacks that will fit your needs best.

chooj's picture

callback

I'm new at maxscript, for now I don't understand how the callbacks work.. But thanx, I'll try to figure it out!

miauu's picture

.

This is how to use it:

(
	global ChangeGAMMASettings_04xhj3
 
	function ChangeGAMMASettings_04xhj3 =
	(		
		if IDisplayGamma.colorCorrectionMode == #gamma then
		(
-- 			EnbGamma.checked = true
		)
		else
		(
-- 			EnbGamma.checked = false
		)	
		print "Gamma changed"
	)
 
	callbacks.removeScripts id:#MaxPreNewSceneNotificationID	
	callbacks.addScript #filePostOpen "ChangeGAMMASettings_04xhj3()" id:#MaxFilePreOpenNotificationID
)

And inside the rollout

global rol_gammachecker
try(destroyDialog rol_gammachecker)catch()
rollout rol_gammachecker ""
(
	checkbox btn_EnbGamma "Gamma enabled"
 
	function ChangeGAMMASettings_04xhj3 =
	(		
		if IDisplayGamma.colorCorrectionMode == #gamma then
		(
			btn_EnbGamma.checked = true
		)
		else
		(
			btn_EnbGamma.checked = false
		)	
		print "Gamma checked"
	)
 
	on rol_gammachecker open do
	(
		ChangeGAMMASettings_04xhj3()
		--	monitor file loading
		callbacks.removeScripts id:#MaxPreNewSceneNotificationID	
		callbacks.addScript #filePostOpen "rol_gammachecker.ChangeGAMMASettings_04xhj3()" id:#MaxFilePreOpenNotificationID
	)
 
	on rol_gammachecker close do
	(
		--	stop monitoring
		callbacks.removeScripts id:#MaxPreNewSceneNotificationID	
	)
)
createdialog rol_gammachecker
chooj's picture

callbacks

why it is necessary to "remove" callbacks script? and why "callbacks.removeScripts" is located before "callbacks.addScript"? can't understand the logic of it.

miauu's picture

.

You have to remove callbacks because it will stay active in current 3dsmax session. So, you may need to use your script(callbacks) whit scene_01.max on which you are working on, but 3 hours later you(without restarting 3dsmax) are ready with the scene_01.max and start working with scene_02.max. The callbacks will stay active, but you may not need it and it can cause problems with scene_02.max.
So, it is prefered to remove callbacks when you will not need them to avoid possible problems.

"callbacks.removeScripts" is located before "callbacks.addScript" just for safe. You have to be sure that the callbacks with approriate ID is removed before to start the callbacks with the same ID, because there is possibility the callbacks with the same name and ID to be already started from someone else(user or script).

The same is the situation with the global variables. You may use my script where I have global variable with name "nextPoint = #()". Then you may start your script where you have the global variable with the same name, but your global variable is a point3("nextPoint = [10, 20, 30]"), not an array(as mine). Since both variables are global and have the same name, they will overwrite themselves. When your global var is used, its value will be point3, when my script uses the same variable it will expect an array, but will receive point3 value, which will causes an error and the script will stop working. The same if the global variable is an array and your script expect point3 value.

chooj's picture

callbacks

thank you for your help! now i understood something.

Comment viewing options

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