Using Python in Nuke to Manipulate Nodes Knob and Strings

In this written tutorial, we will be using Python code within Nuke to manipulate nodes and strings. We will go through the different commands used in the code and explain what they do.

Example: 1 The first part of the code manipulates a string. The string represents a file path
				
					filePath = 'F:/Fiverr/2023/Render/v2/HB_1030_v2_####.exr'
addOne = '/'
addTwo = 'this is test'
print filePath + addOne + addTwo + addOne
# Output: F:/Fiverr/2023/Render/v2/HB_1030_v2_####.exr/this is test/

				
			
Example: 2 In this line, we select the node named “Transform1” and then access the “scale” knob of that node, setting its value to 10
				
					nuke.toNode('Transform1').knob('scale').setValue(10)
print(nuke.toNode('Transform1').knob('scale').value()) 
# Output: 10.0

				
			
Example: 3  Here, we select the same node as before, and access the “clamp” knob, setting its value to 0. This is a boolean value, meaning it can only be either true or false (1 or 0, respectively)
				
					nuke.toNode('Transform1').knob('clamp').setValue(0)
print(nuke.toNode('Transform1').knob('clamp').value())  
# Output: False

				
			
Example: 4 This line selects the “Transform1” node and accesses the “center” knob, which is a two-dimensional array of values. Here, we set the value of this knob to [5, 10], which means that the center of the node will be at coordinates (5, 10) in the viewer
				
					nuke.toNode('Transform1')['center'].setValue([5, 10])
print(nuke.toNode('Transform1')['center'].value())  
# Output: [5.0, 10.0]

				
			
Example: 5 This line selects the “Transform1” node and accesses the “translate” knob, which is also a two-dimensional array of values. Here, we set the value of this knob to [5, 10], which means that the node will be translated (moved) by 5 pixels in the x direction and 10 pixels in the y direction
				
					nuke.toNode('Transform1').knob('translate').setValue([50, 100])
print(nuke.toNode('Transform1').knob('translate').value()) 
# Output: [50.0, 100.0]

				
			

Leave a Comment

Your email address will not be published. Required fields are marked *