我正在为 Nuke 编写一个脚本,以在网格中排列选定的节点。每个节点都有 x 和 y 坐标。这个脚本改变了这些坐标。我想让网格的水平长度为 5,然后开始新的一行。我把它写在一个范围循环中。范围由所选节点的数量决定。我有多个 if 语句将节点放到新行。我的问题是,是否有办法清理 if 语句以减少字面性,并且不必每 5 次重复一次。这是脚本:
list = []
for s in nuke.selectedNodes():
n = s['name'].value()
list.append(n)
names = iter(list)
c = len(nuke.selectedNodes())
for i in range(c):
xNumber = i*200
yNumber = 0
n = i+1
if n > 5:
xNumber = (i-5)*200
yNumber = 200
if n > 10:
xNumber = (i-10) *200
yNumber = 400
if n > 15:
xNumber = (i-15)*200
yNumber = 600
if n > 20:
xNumber = (i-20)*200
yNumber = 800
if n > 25:
xNumber = (i-25)*200
yNumber = 1000
if n > 30:
xNumber = (i-30) *200
yNumber = 1200
if n > 35:
xNumber = (i-35)*200
yNumber = 1400
if n > 40:
xNumber = (i-40)*200
yNumber = 1600
if n > 45:
xNumber = (i-45)*200
yNumber = 1800
if n > 50:
xNumber = (i-50)*200
yNumber = 2000
if n > 55:
xNumber = (i-55)*200
yNumber = 2200
if n > 60:
xNumber = (i-60) *200
yNumber = 2400
if n > 65:
xNumber = (i-65)*200
yNumber = 2600
if n > 70:
xNumber = (i-70)*200
yNumber = 2800
if n > 75:
xNumber = (i-75)*200
yNumber = 3000
if n > 80:
xNumber = (i-80) *200
yNumber = 3200
if n > 85:
xNumber = (i-85)*200
yNumber = 3400
if n > 90:
xNumber = (i-90)*200
yNumber = 3600
if n > 95:
xNumber = (i-95)*200
yNumber = 3800
if n > 100:
xNumber = (i-100)*200
yNumber = 4000
NodeName = next(names)
nuke.toNode(NodeName)['xpos'].setValue(xNumber)
nuke.toNode(NodeName)['ypos'].setValue(yNumber)
该脚本有效,我只是觉得应该有一种更简洁的方式来编写它。