如何在 Foundry Nuke 中获取项目维度?

How to get project dimension in Foundry Nuke?

我正在尝试获取项目的维度 (format),用外行术语来说就是 heightwidth 项目的进一步处理。在 Nuke Python 开发人员指南上阅读有关 Formats documentation 的文档时,我发现要获得项目的宽度和高度,必须 select 脚本中的任何节点,例如

# Viewer1 is only generic thing in every project
nuke.toNode("Viewer1").setSelected(True)
projwidth = nuke.selectedNode().format().width()
projheight = nuke.selectedNode().format().height()

但这对节点图产生了一些不利影响。 Gizmo 已连接到 Viewer1,即使我将 nuke.toNode("Viewer1").setSelected(False) 附加到上述行的末尾也是如此。

Here's 如果您想查看整个脚本的代码。

整个过程看起来很讨厌。我做错了什么吗?可能的解决方法是什么?

您可以使用 Script Editor 中的这一行更改项目的查看器尺寸:

nuke.tcl('knob root.format ' '4K_DCP')

注意root.format后面有个space.

如果您想使用自己的格式(自动),您还应该将这些行放在 init.pymenu.py 文件夹中的 .nuke 中:

import nuke

Format_1600 = "1600 900 0 0 1600 900 1 Format_1600"
nuke.addFormat(Format_1600)
nuke.knobDefault("Root.format", "Format_1600")

其中:1600 900 0 0 1600 900 1 Format_1600 是:

# width = 1600, height = 900
# x = 0, y = 0, right = 1600, top = 900
# pixel aspect = 1 (square pixels)
# name = Format_1600

或者您可以从 nuke 列表中选择任何现有格式:

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()