NOTES ON PARENTING

There are different ways to control one node's value from another one in Nuke.

This is a list of as many ways of doing so as I could just find.

Manually create expression link

1 - Press Ctrl + Right Click on the knob's Animation menu and without releasing it drag and drop it to either on the other knob's where it shows the value (1) or Animation menu (2).

001.jpg

2 - That's it! If you did succesfully you should see the value with a blur overlay which is a sign that the knob is animated ( also that it controlled by an expression ).

002.jpg

3 - You should also see a green line between the two nodes with an arrow that is showing which is a parent and a child node. And also a green circle with an E in the corner of the node that has the expression.

003.jpg

You can also Right click / Edit Expression... on the knob ( or use the = hotkey )

004.jpg

To see that a new value is defined by an expression parent.Blur1.size .

005.jpg

Congratulations! Now you know how to put parenting expression to its place!

giphy003.gif

Codes that create expression lines between two nodes

These are the codes that you can type in the expression dialog to get another knob's value as a result.

010.jpg

1 - This is what you get automatically following a manual way but it has certain shortcomings when it comes to building a gizmo or a template but more about that later.

parent.Blur1.size

2 - The easiest and the quickest.

Blur3.size

3 - Using a same value function that many using on the label to feature certain results works here too!

[value Blur5.size]

4 - Using the knob function will feature a value in this case but if you add another value to it like

[knob Blur11.size 20] that will sets Blur20's size knob to 20 instead of just show a value.

[knob Blur7.size]

5 - This is a python code that requires to switch to python mode on the Expression Dialog by clicking on the Py button.

nuke.toNode('Blur9')['size'].value()

007.jpg

6 - It is a very similar code to the previous one but using a knob function instead of calling a knob as a list item.

nuke.toNode('Blur11').knob('size').value()

7 - Despite that this is a python code you don't need to turn on the python mode but you can tell by typing [python {your py code}] to read it as a python code!

[python {nuke.toNode('Blur13')['size'].value()} ]

8 - It is a very similar code to the previous one but using a getValue instead of the value function.

[python {nuke.toNode('Blur16')['size'].getValue()} ]

Linking channel knobs

In order to link channel knobs you need to click on the Link menu - the little button with

two lines on it - and hit Set link as they don't have animation knob.

012.jpg

You can use a any form of the previous examples, butthis might be the simplest one:

Blur18.channels

When successfully added the code you'll see that the channel knob turned grey and

clicking on the Link menu the options now are Edit link and Remove link.

011.jpg

Setting up expression values with python

As examples the following codes can be run from the Script Editor.

014.jpg

Linking with input values

Using the input function to set value from another node doesn't create expression line on the Node Graphm which makes it visually more difficult to keep track of. Despite that in certain cases, mostly in templates and gizmos it can still be very useful. But be careful with this function as it might cause issues when scripts are getting reassigned and the new artists would have a hard time why

certain values vanished when they change something else. So make sure your script isn't messy!

giphy004.gif
013.jpg

Here are a few more variations that you can use with the input. to get the same result.

015.jpg

input.size

[value input.size]

[knob input.size]

[value this.input.size]

Other thing you can do with input is to move up multiple steps!

You need to use as many input. as many nodes would like to move up.

016.jpg

input.input.input.input.translate.x

As a next step let's see what happens if we don't want to move up on the main pipe only!

For this to work you need to add the serial number of the input. 

By not using a serial number ( as we did before ) it takes the first which is 0 but you can add the number too if want to.

022.jpg

input.input1.input2.input2.size

Let's see how can we do the same with python. ( Don't forget the Py button )

Notice that by using .input() function you need to give an argument ( serial number ) in order to work.

023.jpg

nuke.thisNode().input(0)['size'].value()

We can also move up the node tree using python in a similar way.

Notice that the getting the translate.x value I had to give an argument to a .value() function as that knob holds two values.

024.jpg

nuke.thisNode().input(0).input(0).input(0)['translate'].value(0)

Not so surprisingly at this point you can also use the .input() argument to switch between inputs.

025.jpg

nuke.thisNode().input(0).input(1).input(0).input(2)['size'].value()

Another useful function here worth keeping in mind is .dependencies() which returns a list of nodes that are connected so you can pick the item based on its place on the list.

026.jpg

nuke.thisNode().input(0).dependencies()[-1]['size'].value()

Getting values from the topnode

This is a very useful function in many cases and it's worth knowing few tricks to be able to reach the right topnode in the template! 

Also, there's another article I made about TCL functions in general that are performed on the topnode.

So let's start at the beginning here. By simply calling a topnode that goes up on the first pipes.

027.jpg

[value [topnode].size]

Here's one way to choose which input's topnode you are interested in.

028.jpg

[value [topnode input1].name]

You can combine the topnode and the parent functions to choose which input on which node's topnode you are interested in! After all - there can be sooo many nodes on top!

giphy005.gif
029.jpg

[value [topnode parent.Merge8.input1].size]

Unfortunately, in python there is no equivalent to topnode but as always there are certain ways to get around this issue. The easiest probably is that you can use nuke.tcl() which is the next example.

For more a creative solution I highly recommend to check out Anthony Tan's video on how to re-create the topnode! ( Also to check out his whole py training bcz it is very very useful! )

030.jpg

nuke.tcl("value [topnode].translate.y")

Getting values from outside the Group

Often, when you are working on new gizmos you need to get certain values from outside the Group. Luckily, there are some ways to do that!

Probably, the most useful parenting expression in a gizmo is when checking if the input has something connected or not. This is often useful added to the disable knob. This code also contains ! and exists which are conditional expression - you can find out more about those here.

031.jpg

![exists parent.input1]

Hope you will find it useful!