[Closed] NitrousGraphicsManager
Hi,
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 ?
Thanks
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 ?
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.
-Eric
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
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
)
)
-Eric
Hi,
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
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