Setting Width and Height of a Constant node in NUKE

Viewed 655

I am trying to link the Read node format of my input images to a Constant node down the tree as I am trying to process a bunch of images with varying resolutions and aspect ratios.

I tried Ctrl dragging the format from the Read node to the Constant node to have it update if that is even a thing I can do.

I am fairly new to Nuke if you can't already tell.

2 Answers

It's quite easy to do what you need: Just create two nodes – Read1 (with some content) and Constant1 and execute the following code in NUKE's script Editor:

import nuke

sourceWidth = nuke.toNode("Read1").width() 
sourceHeight = nuke.toNode("Read1").height() 
nuke.tcl('add_format "%s %s temporaryResolution"' % (sourceWidth, sourceHeight)) 

nuke.toNode("Constant1").setSelected(True) 
nuke.createNode("Reformat")['format'].setValue('temporaryResolution') 

Aa a result you'll get a Reformat node connected to Constant1 with new width and height values.

You can avoid this problem entirely by just not using the Constant node, and instead make a blank image from your source imagery - that way it automatically inherits the input format.

Put differently, say you have something like so:

Constant approach

The constant has no input, therefore it has to specify a format - but all it does is make an empty image. What we want is a blank image but with the same format as the source image, so instead we can start with the source image, and simply remove all the channels (Remove node set to "channels: all"), then a Shuffle to recreate the default rgba layer. Something like so:

Blanking pipe approach

This way no scripting is required, so the problems of when the format-linking expressions are evaluated is avoided

Related