1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python节点 Nuke Python 控制节点图

python节点 Nuke Python 控制节点图

时间:2023-03-06 18:00:38

相关推荐

python节点 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 )

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。