我对 Python 比较陌生,我需要一些帮助。这也是我在这个网站上的第一篇文章。我正在尝试更改“读取节点”中标记为“Plate”的颜色空间旋钮的值。我想稍后使用该值。这是到目前为止我的代码:
def LabelPlate():
n = nuke.thisNode()
if n != None:
label = n['label'].value()
n['label'].setValue('Plate')
def LabelLook():
name= "Plate"
for node in nuke.allNodes():
if name == node.knob("label").value():
return True
def LabelLookTwo():
name= "Plate"
for node in nuke.allNodes():
if name == node.knob("label").value():
return node.knob("name").value()
def PlateColorspaceSet():
n = LabelLookTwo()
if nuke.toNode("n")["colorspace"].value() == "default (sRGB)":
nuke.toNode("n")["colorspace"].setValue("sRGB")
def LabelQuestion():
if LabelLook() != True:
if nuke.ask('Is this Read your main Plate?'):
LabelPlate()
PlateColorspaceSet()
nuke.addOnUserCreate(LabelQuestion, nodeClass = 'Read')
事件顺序:
- 引入读取节点
询问读取节点是否是您的主板
a.如果是,则将节点标记为“Plate”,继续执行步骤 3
b.如果不是,则引入未标记的读取节点将标记为“Plate”的节点中的色彩空间从默认值更改为实际值。
到目前为止,我可以完成前两个步骤。但在第 3 步,我得到了
"'NoneType' object has no attribute 'getitem'"
有什么想法吗?有没有更好的方法来获取色彩空间值?
最佳答案
我发现了问题。
nuke.addOnUserCreate 是我在创建读取节点时调用函数的地方。问题是,它在一切都存在之前运行脚本。所以并不是所有东西都能工作,因为 Nuke 中还没有所有东西,所以像我的变量 n = LabelLookTwo() 这样的东西,返回为 None。
使用 addOnCreate 会在节点及其默认值设置和创建后运行脚本。因此,使用它,脚本的其余部分将完全按照最初编写的方式运行。
关于python - Nuke Python 获取 if 语句的旋钮值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31254401/