Use of the Nuke Python module

Source: Internet
Author: User

Much of the recent scripting work needs to run out of the nuke GUI environment, and without script Editor, you have to try nuke the Python module feature. This mode can perform most of the commands in the GUI environment and is highly efficient when automatically generating or batching nuke projects.

The following is a brief description of the pattern:

Starting with version 8.0, nuke can be used as a Python module.

This means that you can now use Python in the VFX process to do a lot of complicated things, for most 2DPython modules, 3DPython modules, and video editing Python modules, this is an easy-to-use, product-level, incredible, and powerful alternative.

Ignoring the Python version, by nuke you can now use the Python.exe interpreter instead of the Nuke.exe to fully invoke nuke Python-api to programmatically synthesize. This means that you can do things in a python way, such as quickly toning 2000 shots, or changing the time of a series of fade effects based on the clip time list with five or six lines of code. You can more easily connect nuke to your underlying back-end code, integrate nuke into your process, and even put nuke into other applications.

To use nuke as a Python module, you need to use a Python interpreter that is loaded with nuke (this module should work with other interpreters, but is officially supported with nuke).

As a standard Python module, you can either use the interpreter interactively or let it execute code scripts directly.

You can do this by:

<nuke8.0-install-path>$ Python.exe xxx.py

This way to execute the py script, or by:

<Nuke8.0-install-path> $Nuke 8.0v5.exe–t xxx.py

To execute the PY script, or by:

<Nuke8.0-install-path> $Nuke 8.0v5.exe–x xxx.py

To execute the PY script.

In fact, in the next two methods, Nuke is executed as a Python interpreter by using the-t parameter.

Three methods are the same, the core is the Python interpreter.

Here's a quick example:

classNukescriptoperator ():
Script_path= Os.path.dirname (Cmds.file (q =1, location = 1)) +'/' ifOs.path.exists ('C:/Program files/nuke8.0v5/'): Nuke_folder='C:/Program files/nuke8.0v5/' elifOs.path.exists ('C:/Program files/nuke8.0v1/'): Nuke_folder='C:/Program files/nuke8.0v1/' elifOs.path.exists ('C:/Program files/nuke9.0v1/'): Nuke_folder='C:/Program files/nuke9.0v1/' elifOs.path.exists ('C:/Program files/nuke9.0v5/'): Nuke_folder='C:/Program files/nuke9.0v5/' Else: Nuke_folder=Nonedef __init__(self,script,firstframe,lastframe): Self.script=Script Self.firstframe=firstframe Self.lastframe=Lastframe Self. Sourceseqs=NonedefWriterenderscript (self): Commandstr="#-*-Coding:utf-8-*-\nimport nuke\nimport sys\nnuke.scriptopen ('%s ') \nwritenode = Nuke.tonode (' Write1 ') \NP = Os.path.dirname (Nuke.tonode (' Write1 ') [' File '].value ()] \nif not os.path.exists (p): \ n os.makedirs (p) \nfirstframe =%s \nlastframe =%s\nnuke.execute (WriteNode, Firstframe, lastframe) \nprint ' success! '"%(self.script,self.firstframe,self.lastframe) F= Open (Script_path +'render.py','W') F.write (COMMANDSTR) f.close ()defExecutepyscript (self):ifNuke_folder = =None:returnNone Nukecommand="%s/python.exe%s%s.py"%(Nuke_folder, Script_path, pyscript) Subpopen= subprocess. Popen (Nukecommand, CWD =Nuke_folder)returnNone

First build a class named Nukescriptoperator, add Writerenderscript () and Executepyscript () two methods, where the Writerenderscript () class is used to generate a py script that performs rendering , the Executepyscript () method is used to perform rendering.

where Executepyscript () Nukecommand = "%s/python.exe%s%s.py"% (Nuke_folder, Script_path, Pyscript)

is to generate a commandline command, which is then passed to subprocess. The Popen () method executes.

Use of the Nuke Python module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.