Get and set a nuke Read node's resolution from python script

1.9k views Asked by At

I'm running a nuke nk file from the command line through a python script. E.g. nuke -nukex -i -t [myPythonScript.py] [myNukeFile.nk] [otherParams]

I'm pretty new to nuke but I am able to set various knob values from python for this nk script and run its write node, but how do I set the render resolution so I can change the render output image size?

What's the best way to resize and how? The Read node has the format knob but a). it is a dropdown for presets and I'd prefer giving it an actual resolution number, and b). setting it doesn't seem to work: readNode.knob("format").setValue("square_256") # doesn't work

Bonus points also if someone explains how would I form python resize and zoom the viewport (render region) as well :)

1

There are 1 answers

0
Erwan Leroy On BEST ANSWER

There are quite a few ways to control the image size, and it sort of depends on the content of your nuke script. Using the Read node's format knob is not one of them, this is only really used to calculate proxy size or set a default resolution when the source images are missing.

If things are generated in nuke, they will generally default to the root format, which you can control in python as explained here: https://learn.foundry.com/nuke/developers/113/pythondevguide/formats.html

# CREATE A NEW FORMAT
square2k = '2048 2048 square2k'
nuke.addFormat( square2k )

# SET THE ROOT TO USE BOTH BASE AND PROXY FORMATS
root = nuke.root()
root['format'].setValue( 'square2k' )

If you are reading images, Nuke will use your image resolution. In order to resize it, you need to use a reformat node. The Resize node can either use an existing format, or you can change the type to to box, check "force this shape" (box_fixed knob in python), and set your desired width and height. You can also change the resize type and filtering as desired.