【发布时间】:2020-01-03 01:58:32
【问题描述】:
所以为了简单起见,我在 NUKE 中编写了一个脚本,它将节点图中的选定节点对齐到 Y 轴上的一条直线上。我在编写 elif 语句时遇到问题,该语句要么没有按我想要的方式运行,要么给我一个语法错误。
所以函数的基础是:
ELSE STATEMENT - 仅选择一个节点时 - 弹出错误消息说用户必须选择多个节点
ELIF STATEMENT - when selected two or more nodes which are in the same Y-axis - message showing they are already aligned
IF STATEMENT - when selected two or more nodes in different Y-axis - it should properly align all the nodes in a straight line
# Getting selected nodes and making them into a list
selNodes = nuke.selectedNodes()
list = []
for node in selNodes:
n = node['ypos'].value()
list.append(n)
# Defining the actual function
def alignY():
# Aligning the selected nodes using average position of every node.
# Must select more than one node in order to get an average.
if len(selNodes) > 1:
total = sum(list)
average = total / len(selNodes)
for node in selNodes:
n = node['ypos'].setValue(average)
# Getting the position of a single node from the list
firstNodePostion = list[0]
# Checking position of the single node is equivalent to the average
# To prevent nodes aligning again)
elif average == firstNodePostion:
nuke.message("Nodes already Aligned")
# When no nodes or only one node is selected this message pops up
else:
nuke.message("Select Two or more Nodes")
alignY()
【问题讨论】:
-
欢迎堆栈溢出!不幸的是,您的问题陈述不清楚。 “要么没有按我的意愿运行,要么给我一个语法错误”-请描述行为有何不同,并提供您收到的错误的完整追溯 从表面上看,您可能有缩进问题或未缩进的行破坏了 if 和 elif 之间的连接
-
您的代码 sn-p 无效(缩进损坏),因此没有人能理解它。请使用 proper minimal reproducible example. 编辑您的问题
标签: python python-2.7 nuke compositing