Nuke Python 控制节点图

使用python你可以干下面的事:

  • 读取、设置节点位置的属性
  • 控制节点图的推拉

在Nukepedia上有一个视频教程

读取、设置节点位置

通过其knob可以存取节点的x y位置

node = nuke.createNode( 'NoOp' )
print node['xpos'].value()

使用常用的knob方法设置新位置:

node['xpos'].setValue(100)
print 'new position is', node['xpos'].value()

获取位置的其他方法:

node.setXpos( 111 )
node.setYpos( 222 )

xPos = node.xpos()
yPos = node.ypos()
print 'new x position is ' , xPos
print 'new y position is', yPos

同时设置x y

node.setXYpos( 123, 234 )

在缩放1的情况下获取节点像素的宽,高

nodeWidth = node.screenWidth()
nodeHeight = node.screenHeight()

print "node dimensions are %s x %s" %( nodeWidth, nodeHeight )

自动安排节点,不重叠:

for n in nuke.allNodes():
    n.autoplace()

将节点吸附到最近的节点:

for n in nuke.allNodes():
        nuke.autoplaceSnap( n )
控制节点图的缩放

为了缩放,缩放节点图,用nuke.zoom()
当没有参数时,这将返回当前缩放值:

nuke.zoom()

大于0的参数,节点图就放大到相应倍数。例如,将视口重新设置为1:1:

nuke.zoom( 1 )

也可以指定缩放的中心,缩放到指定节点:

node = nuke.selectedNode()
nuke.zoom( 3, [node.xpos(), node.ypos() ])

上面的例子缩放到节点的左上方。缩放到节点中间

node = nuke.selectedNode()
xC = node.xpos() + node.screenWidth()/2
yC = node.ypos() + node.screenHeight()/2
nuke.zoom( 3, [xC, yC] )
例子
用Dot节点做的圈圈
import math
for x in xrange(1000):
        n = nuke.node.Dot( xpos = math.sin(x)*100, ypos = math.cos(x)*100 )
        n['hide_input'].setValue(True)
螺旋
import math
for x in xrange(1000):
    n = nuke.nodes.Dot( xpos = math.sin(x)*x/10, ypos =math.cos(x).x/10)
    n['hide_input'] .setValue(True)
控制节点间距
import nuke
def scaleNodes( scale ):
    nodes = nuke.selectedNodes()
    amount  = len( nodes)
    if amount ==0:
        return

    allX = sum([n.xpos() + n.screenWidth()/2 for n in nodes]
    allY = sum( [n.ypos() + n.screenHeight()/2 for n in nodes]

    centreX = allX / amount
    centreY = allY / amount

    for n in nodes:
        n.setXpos( centreX + (n.xpos() - centreX )*scale )
        n.setYpos( centreY +(n.ypos() - centreY) * scale )
scaleNodes( 3)
scaleNodes( .7 )
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,080评论 19 139
  • 使用下文描述的nuke.add...()函数,当有变量事件(比如,创建节点,加载脚本)时就自动调用python函数...
    N景波阅读 2,837评论 0 1
  • 怎么创建roto 图形和 画笔当获取或者设置roto,rotopaint节点时,需要读取节点的curves kno...
    N景波阅读 1,667评论 0 1
  • 铃铛孤单晃响谜底曾在沙棘的汁液里一颗星星、四五个太阳孤掌印记填满沧海桑田那年月下不可见的风骨在指尖 在瞳仁融化
    一客温阅读 177评论 0 0
  • 曾经写过很多诗,没有交给你。 本想留做珍藏在心底的, 那美好的回忆。 曾经写过的那些诗, 那日那月那年的记忆。 还...
    FIYINGing阅读 245评论 6 9