美文网首页CgTd
Nuke Python 使用命令行

Nuke Python 使用命令行

作者: N景波 | 来源:发表于2016-11-22 11:40 被阅读0次

nuke的命令行如何执行python脚本,请听详细分解

在python模式下运行nuke

通过 -t 参数,可以在python解释器中运行nuke

/Application/Nuke6.3v1/Nuke6.3v1.app/Nuke6.3v1 -t

可在 -t 后添加 启动脚本:

./nuke6.3v1 -t <mypythonscript.py>
使用命令行参数

nuke运行python脚本时,脚本参数通过sys.argv 传入,例如运行test.py:

import sys, nuke
print sys.argv

在命令行下运行此脚本,查看包含参数

./Nuke6.3v1 -t test.py hello wrold

 ['test.py', 'Hello', 'world' ]

唯一的特例就是,参数以帧号结尾的:

./nuke6.3v1 -t test.py hello world 1,20

此种情况,1,20被sys.args分开,被保存在了 nuke.tcl('frames all')中查看所有参数:nuke.rawArgs

例如,编辑test.py

import sys, nuke
print nuke.rawArgs

./nuke6.3v1 -t test.py hello world 1,2

结果:

    ['/Application/Nuke6.3v1/nuke6.3v1.app/nuke6.3v1', '-t', 'test.py', 'hello', 'world', '1,2' ]
修改现有nuke脚本
有时候修改nuke现有脚本也是有好处的,比如重写文件路径:
在命令行打开nuke脚本,重写路径,保存。
# save this file as replaceWritePaths.py
import nuke
import os
import sys

def RecursiveFindNodes( nodeClass, startNode ):
        if startNode.Class() == nodeClass:
                yield startNode
        elif instance( startNode, nuke.Group ):
                for child in startNode.nodes():
                    for foundNode in RecursiveFindNodes( nodeClass, child ):
                            yield foundNode

if len( sys.argv ) 1=5:
    print 'Usage: nuke replaceWritePaths.py <nuke_script> <new_nuke_script> <in_file_pattern> <new file pattern>'
    sys.exit(-1)

inScript = sys.argv[1]
outScript = sys.argv[2]
inPattern = sys.argv[3]
outPattern = sys.argv[4]

nuke.scriptOpen( inScript )

allWriteNodes = [ w for w in RecursiveFindNodes('Write', nuke.root() )]

for write in allWriteNodes:
    path = write['file'].value()
    path = path.replace( inPattern ,outPattern )
    write['file'].setValue( path)

nuke.scriptSave( outScript )

以上脚本运行语法如下:

./Nuke6.3v1 replaceWritePaths.py <nuke_script> <new_nuke_script>
  • <in_file_pattern> <new_file_pattern>
  • <nuke_script> is the script to read in
  • <new_nuke_script> is the name to save the modified script to
  • <in_file_pattern> is string to search for in all the write file paths
  • <new_file_pattern> is the string to replace <in_file_pattern> in all the write file paths
执行帧序列

当在-t python模式下运行nuke时,其不会渲染和执行任何node
想渲染一个节点,就得这样来:

nuke.execute( nodeName, firstFrame, lastFrame )

当以-x 参数运行时,就切换到渲染帧序列模式,用python脚本,而不是nuke脚本(.nk),nuke执行python脚本先,随后用给定的帧范围渲染所有的writes。例如运行 convert.py脚本:

import sys
import nuke
r = nuke.nodes.Read( file = sys.argv[1] )
w = nuke .nodes.Write( file = sys.argv[2])
w.setInput( 0 ,r )

现在从命令行运行脚本,将5帧jpegs转换成tif

nuke6.3v1  -x  convert.py  myfiles.###.jpg  myfiles.###.tif  1,5

相关文章

  • Nuke Python 使用命令行

    nuke的命令行如何执行python脚本,请听详细分解 在python模式下运行nuke 通过 -t 参数,可以在...

  • Nuke Python 回调函数

    使用下文描述的nuke.add...()函数,当有变量事件(比如,创建节点,加载脚本)时就自动调用python函数...

  • Nuke Python 作为包使用

    从8.0开始Nuke能作为python的一个模块用了。意味着在VFX流程中可以用python做很多以前做不了的复杂...

  • Nuke Python 入门

    本章的例子帮你初步了解Nuke Python API的使用。 脚本大小写敏感,需要输入正确才能运行。拷贝时注意缩进...

  • Python库

    docopt Python的命令行解析库,可以自定义一条命令行命令,使用命令行执行你的python程序

  • 百度小程序转换微信小程序

    Python脚本,一键转换Github地址 运行条件 具备Python环境,可在命令行中使用Python命令 使用...

  • Day 2(Python + Vim)

    学习Python,在本机搭建Python编程环境,学会基本的Python语法(学习过程中使用Vim编写,使用命令行...

  • python命令之m参数 局域网传输

    在命令行中使用python时,python支持在其后面添加可选参数。 python命令的可选参数有很多,例如:使用...

  • 【python】‘图片转字符画’实验,安装pip中的Pillow

    在Python3.X中在命令行使用PIP安装:pip install Pillow (尝试可行) 或在命令行使用...

  • Nuke Python 用PyQt扩展Nuke

    虽然nuke内置了pyside,但是想用pyqt还是可以的。配置pyqt需要几个步骤,当然Python26也要安装...

网友评论

    本文标题:Nuke Python 使用命令行

    本文链接:https://www.haomeiwen.com/subject/kcmppttx.html