nuke的可组合上下文管理器库
nukecontexts的Python项目详细描述
nukecontexts是一个可组合上下文管理器库,用于nuke管理代码中复杂合成脚本的状态。
安装
要安装nukecontexts,请键入:
$ pip install nukecontexts
打开nuke的init.py文件并添加:
nuke.pluginAddPath('/path/to/your/local/python/site-packages')
开始
nukecontexts最常见的用例是自动呈现合成脚本的多个状态。例如两种不同的输出格式,jpg和png。
importnukefromnukecontextsimportctxrender_node=nuke.toNode('Write1')withctx.set_attr(render_node,'file_type','jpeg'):nuke.execute(render_node.name(),1,1,1)withctx.set_attr(render_node,'file_type','png'):nuke.execute(render_node.name(),1,1,1)
nukecontexts的威力来自于使用multiple_contexts()的可组合上下文。可以定义任意复杂、变化的合成脚本状态,并用于自动生成不同的结果。
merge_node=nuke.toNode('Merge1')grade_node=nuke.toNode('Grade1')switch_node=nuke.toNode('Switch1')ctx1=ctx.enable([merge_node,grade_node])ctx2=ctx.set_attr(grade_node,'white',2.0)ctx3=ctx.set_attr(switch_node,'which',0)ctx4=ctx.disable(merge_node)withctx.multiple_contexts([ctx1,ctx2,ctx3]):"""Render with the merge_node and grade_node enabled, the grade_node's white attribute set to 2.0 and the switch_node's switch position set to 0."""nuke.execute(render_node.name(),1,1,1)withctx.multiple_contexts([ctx3,ctx4]):"""Render with the switch_node's switch position set to 0 and the merge node disabled; the grade_node's gain value remains at the original value."""nuke.execute(render_node.name(),1,1,1)