$GUI vs. EXECUTING()
This page is an ongoing comparison of 2 useful snippet of codes that helps you
manage heavy scripts.
The common thing is that both of the functions asks a question that is either
False or True aka 0 or 1.
This expression is asking a question when you use it -
Is the Graphic User Interface ( = GUI ) is in use or not?
When it is the value is True aka 1, and when it isn't the value is False aka 0.
This is a very useful snippet when you have some heavy nodes of your script and only want to render them on the farm ( which is a situation
when the script is active but no user interface is in use ).
So let's see how to use it in a common situation when you have a heavy node and would like to render only on the farm so
would add this to the 'disable' knob:
1. Right click on the 'disable' knob and select 'Add expression..'
2. In the Expression window can type now $gui and hit OK.
3. If everything is fine you'll see that the knob turned blue and your node has an E in the corner.
4. If you want to remove the expression, right click on the knob and select 'No animation'.
If you want you can also assign different values than 0 and 1.
In this case using a '?' you can ask if the user interface is True THEN use the value 5 ELSE use 50.
If for some reasons you want to reverse the value, you can put
an exclamation mark ( ! ) before the $gui.
To dive deeper into how powerful this function is let's use some python!
Using python we can assign expression values to knobs where we can't do manually otherwise.
In the following example we use it on the ScanlineRender's 'antialiasing' knob in order to see with 'none' while we are working and 'high' on the render.
( If you are new to Python in Nuke I recommend this tutorial you might find useful. )
And here is another very useful snippet that I found a while ago here.
It prints the name of the nodes and knobs that has $gui as a value:
This function is relatively new as it was introduced quietly with Nuke v11 on the API.
In theory it works very similarly as $gui except that it also works on local renders
which is a huge benefit. Unfortunately, the downside is that it doesn't work always as expected.
The reason is something that I am still trying to figure out but with this post I would like to
inspire some more experiments as this function seems a worty rival of the $gui.
But first let's see how can you use it!
So if you open the Expression window as mentioned earlier and just type in
the code you will receive an Error message.
To fix this on the right side of the window you can turn Off the 'R' button and On the 'Py'
so it will read the input as a python code.
If you want to reverse the values just put 'not' before the code.
If you need different values than 0 and 1 can use an If statement.
If you need to use the code as an expression can use this formula.
Another useful and safe application for both codes is to apply it in a Switch node.
If you need a ready made gizmo for this purpose you can get a Render Switch
that I built earlier using executing().
So as a downside so far I found that this function doesn't work with a
ScanlineRender's 'antialiasing' knob for some reasons.
Altough it does work with other dropdown menus I tested on so far.
In order to get to the bottom of this feel free to join the converstaion on the Foundry Forum here!
A story about the importance of the following point first:
A few years ago I inherited a script from someone who left the studio.
The script was large and vaguely organized and I was only asked to do some
minor changes so there was no point rebuilding anything.
The problem was that the latest render didn't match
with the part the latest Write node was connected to.
First, I started to look around in the script for parts that might match with the missing part.
( At a time it didn't occur to me that what I was looking for might have been disabled. )
Then I questioned if the pipeline worked well or accidentally dropped the latest script somewhere else?
Didn't find anything that would help so asked my Lead.
After the first half on hour he had a hunch of what's might going on.
He started to search through the nodes that had a little E in the corner.
Eventually, found the culprit as one of the nodes had a $gui in a `disable` knob.
This was a first time I heard about the $gui.
I wasn't happy about it as it just cost me half a day of work that I spent with aimless search.
I am sure many compositors found out about the existence of this code the similar
way which is rather frustrating. Therefore many has mixed feelings about this function
although these can be great allies for us to be more effective.
Luckily, there is a simple solution to avoid these situations:
! JUST USE THE LABEL !
Here are two equally good ways but you can be more creative than that.
The point is only that if you are using any of these functions don't fail to
indicate in a very very obvious way!
Hope you will find it useful!