Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 04 April 2013   #1


I'm trying to create a toggle button to switch between realistic and the previous visual style the active viewport was on.

In theory it is very simple using NitrousGraphicsManager.GetActiveViewportSetting() and a #viewportChange callback used to get the current style of the active viewport.

Basically the toggle works like this:

If the active viewport is already in realistic mode, i want the toggle to automatically reflect this, and so be "on", and if the viewport has another style the toggle is "off" and clicking on it will switch to realistic, clicking again will revert to the previous style. Very simple.

And i succeeded... until i restarted max which throw me a bunch of errors.

The problem is that the macroscript for the button is evaluated BEFORE the viewports even exists : the variable which will handle the visual style is still undefined and so the toggle can't decide if it is on or off...

So my question is : how could i do to postpone the evaluation of the macroscript AFTER the first redraw of the viewport and so avoiding this error ?


Old 04 April 2013   #2
try using a #postSystemStartup callback.
Old 04 April 2013   #3
Hm, but the toggle is located in the statubar, and the initial state of the toggle (on ischecked do...) must be true or false at the moment the script is evaluated (which cause the error, because my variable, the style of the active viewport, is still undefined)...
I don't see how I can handle this with a callback... Any idea ?
Old 04 April 2013   #4
You can wrap it in a try/catch. Or you can use the PostSytemStartup to define a variable as true, and have the Macroscript only evalute/available if that PSS callback variable is true.

"The Evil Monkey hiding in your closet."
Old 04 April 2013   #5
Originally Posted by PiXeL_MoNKeY: You can wrap it in a try/catch. Or you can use the PostSytemStartup to define a variable as true, and have the Macroscript only evalute/available if that PSS callback variable is true.


Thanks, the first one i used it, but it doesn't solve the problem as the toggle doesn't switch to the correct state (it only avoid throwing errors at startup).

The second seems the way to go and i was looking in that direction but i have absolutely no idea how i could use the PostSytemStartup callback to postpone the evaluation of this particular macroscript. Any clues would be greatly apreciated.

Thanks again
Old 04 April 2013   #6
You could try something like this:
callbacks.addscript #postSystemStartup "PSScb = MacroName.isenabled = true" -- enable the button and code
callbacks.addscript #preSystemShutdown "PSScb = MacroName.isenabled = false" -- disable the button and code
Macroscript MacroName
	if PSScb do
		--Macro code here

"The Evil Monkey hiding in your closet."
Old 05 May 2013   #7

Thanks and sorry for my late answer : i wasn't "online" yesterday.

I have tried your code, but it doesn't work : my guess is that the macroscript name can't be used as it is not a variable... or i am too much dumb to implement this correctly.

I have no clues
Old 05 May 2013   #8
Ok, I succeeded and the solution was finally in fact easy :

It indeed works when using a #postSystemStartup callback which trigger the function evaluating the style of the viewport (shaded or realistic). But the callback script must be located in the startup script folder.

To make the toggle dynamic, ie : when clicking another viewport, the toggle must reflect the style of that viewport, i just created another #viewportChange callback which update the toolbar buttons. This part is a little dirty, but i couldn't find another way for the macroscipt to be re evaluated.

Thanks peoples for puting me on ther right track
Old 05 May 2013   #9
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:26 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.