I'm trying to get the dimension of the project (format
), which, in the layman term height and width of the project for further processing. While reading documentation on Formats documentation on Nuke Python developer's guide, I found that to get the width and height of project, one must select any node in script, e.g.
# Viewer1 is only generic thing in every project
nuke.toNode("Viewer1").setSelected(True)
projwidth = nuke.selectedNode().format().width()
projheight = nuke.selectedNode().format().height()
But this produces some adverse effect on the node graph. The gizmo is connected to Viewer1, even if I append nuke.toNode("Viewer1").setSelected(False)
to the end of the above line.
Here's the code if you want to see the whole script.
This overall process seems so nasty. Is there anything wrong I'm doing? What could be the possible fix?
You can change the project's Viewer dimensions using this line in Script Editor
:
nuke.tcl('knob root.format ' '4K_DCP')
Pay attention there is a space
after root.format
.
Also you should put these lines in init.py
or menu.py
in .nuke
folder if you wanna use your own format (automatically):
import nuke
Format_1600 = "1600 900 0 0 1600 900 1 Format_1600"
nuke.addFormat(Format_1600)
nuke.knobDefault("Root.format", "Format_1600")
Where: 1600 900 0 0 1600 900 1 Format_1600
is:
# width = 1600, height = 900
# x = 0, y = 0, right = 1600, top = 900
# pixel aspect = 1 (square pixels)
# name = Format_1600
Or you can choose any existing format from nuke list:
nuke.knobDefault('Root.format', 'HD_1080')
And, of course, you can
get
dimensions and other values of the project's format:
nuke.root()['format'].value().width()
nuke.root()['format'].value().height()
nuke.root()['format'].value().name()
nuke.root()['format'].value().pixelAspect()
nuke.root()['format'].value().x()
nuke.root()['format'].value().y()
nuke.root()['format'].value().r()
nuke.root()['format'].value().t()