Skip to content
Alan Dann edited this page Apr 16, 2014 · 29 revisions

The Nuke Write Node App provides a custom Shotgun Write node which makes it easy to standardise the location where images are rendered to. It can be configured for each environment. In addition to the path, the configuration will also determine the render format to be used.

General Use

In order to use the Shotgun Write Node, save your script as a Toolkit work file first and then create a new node via the Nuke menu. This will create a node which looks similar to a normal write node:

![Write Node](images/write_node_creation.png)

Rather than entering a path by hand, you just specify an output name and Toolkit will then compute the rest of the path automatically. You can see the computed path in the UI and open up the location on disk by clicking the Show in File System button. The location where the renders are written to depends on the Toolkit configuration.

The renders will be versioned and the version number will always follow the current nuke script version which will be incremented automatically when you publish using Multi Publish.

Resetting the render path

The Write Node will cache the current path so that it is still valid if the file is opened outside a Toolkit Work Area. Occasionally, this can mean that the path becomes out of sync and 'locked'. If the render path is locked then renders created with this Write Node cannot be published.

To reset a render path, either version-up the scene using the Work-files app's 'Version Up Scene' command or select the Write node individually and in the properties, click Reset Path:

![Write Graph](images/write_node_reset_path.png)

Adding Another Write Node Profile

The Shotgun Write Node wraps Nuke's built-in write node, so any format supported by Nuke can be used with the app and additional nodes can be added via configuration. The simplest way to start is to set up a simple Nuke write node with the parameters you want. For the example, let's imagine you are doing 16-bit tifs with LZW compression. If you look at your Nuke script in a text editor, the write node will look something like this:

Write {
    file /Users/ryanmayeda/Desktop/test.%04d.tif
    file_type tiff
    datatype "16 bit"
    compression LZW
    checkHashOnRead false
    name Write1
    xpos -145
    ypos -61
}

The text will tell you what the parameter names and values you need are. In this case it's datatype and compression. Next, go into your environment configuration (for example: /path/to/pipeline/config/env/shot.yml). Find the area where the tk-nuke-writenode app is configured, and add another Write Node, with these two parameters in the settings:

tk-nuke-writenode:
  location: {name: tk-nuke-writenode, type: app_store, version: v0.1.6}
  template_script_work: nuke_shot_work
  write_nodes:
  - file_type: exr
    ...
  - file_type: dpx
    ...
  - file_type: tiff
    name: Mono Tif
    publish_template: nuke_shot_render_pub_mono_tif
    render_template: nuke_shot_render_mono_tif
    settings: {datatype: 16 bit, compression: LZW}
    tank_type: Rendered Image

The updated configuration will then result in the additional Shotgun Write Node appearing in Nuke:

![Add New](images/write_node_add_new.png)

Render Farm Integration 1

It's common for studios to use a render farm running job management tools (e.g. Deadline) which would typically launch Nuke directly when rendering. Because this is outside of the Shotgun environment, the tk-nuke-writenode app and the Write Node gizmo will not be found without some additional help.

Whilst we are experimenting with a more complete solution, the following is a minimal bootstrap of the tk-nuke engine so that Shotgun Write Nodes behave as expected.

Bootstrap the Shotgun Pipeline Toolkit engine using init.py

Nuke will run any init.py scripts found in it's plug-in path - see [here http://docs.thefoundry.co.uk/nuke/63/pythondevguide/startup.html ] for more details.

The following example init.py script should be placed in one of these locations and this will ensure that the tk-nuke engine is loaded correctly.

# Save this file as init.py in your nuke plug-in path as described here:
#
#   http://docs.thefoundry.co.uk/nuke/63/pythondevguide/startup.html
#

# Tell the script where the Toolkit Core API is installed.
# This is often referred to as the 'studio' location.
# Don't forget back slashes in the windows path!

SGTK_STUDIO_LOCATION_LINUX   = "/mnt/software/shotgun/studio"
SGTK_STUDIO_LOCATION_MAC     = "/mnt/software/shotgun/studio"
SGTK_STUDIO_LOCATION_WINDOWS = "z:\\mnt\\software\\shotgun\\studio"

# Tell the script where the project root is located. 
# This location will be used if no .nk file is specified on the command line

SGTK_DEFAULT_WORK_AREA_LINUX   = "/mnt/projects/my_project"
SGTK_DEFAULT_WORK_AREA_MAC     = "/mnt/projects/my_project"
SGTK_DEFAULT_WORK_AREA_WINDOWS = "z:\\mnt\\projects\\my_project"


def init_sgtk():
    """
    Minimal setup to ensure the tk-nuke engine is up
    and running when Nuke is started outside or the
    Tank command or Shotgun context menus 
    """    
    import sys, os

    studio_map = {"linux2": SGTK_STUDIO_LOCATION_LINUX,
                  "win32":  SGTK_STUDIO_LOCATION_WINDOWS,
                  "darwin": SGTK_STUDIO_LOCATION_MAC }

    work_area_map = {"linux2": SGTK_DEFAULT_WORK_AREA_LINUX,
                     "win32":  SGTK_DEFAULT_WORK_AREA_WINDOWS,
                     "darwin": SGTK_DEFAULT_WORK_AREA_MAC }

    # make sure sgtk module can be found in the python path:
    core_python_path = os.path.join(studio_map[sys.platform], "install", "core", "python")
    if core_python_path not in sys.path: 
        sys.path.append(core_python_path)

    # Check that we need to start the engine:
    if "TANK_ENGINE" in os.environ:
        # tk-nuke engine is going to be set up by
        # tk-multi-launchapp so we don't need to bother
        return

    # Check that the engine isn't already running
    if "TANK_NUKE_ENGINE_MOD_PATH" in os.environ:
        # tk-nuke engine is running which will handle all 
        # engine & context management from now on
        return

    # initialize tk-nuke engine:
    try:
        # Determine the work area path that will be used to
        # create the initial context the engine will be
        # started with.  If a file path was specified on the
        # command line then this will be sys.argv[0]
        work_area_path = work_area_map[sys.platform]
        if len(sys.argv) > 0 and sys.argv[0].endswith(".nk") and os.path.exists(sys.argv[0]):
            # file path was passed through the command line
            work_area_path = sys.argv[0] 

        import sgtk
        tk = sgtk.sgtk_from_path(work_area_path)
        ctx = tk.context_from_path(work_area_path)
        sgtk.platform.start_engine("tk-nuke", tk, ctx)
    except Exception, e:
        print "Failed to start Toolkit Engine - %s" % e

init_sgtk()

You will need to modify this script to provide your specific studio/code and project roots - you may also need to extend this if your configuration is more complex than this example or you are passing a python script to the command line using the -t flag instead of a nuke (.nk) script.

Deadline Specific

Deadline can copy Nuke scripts to a temporary location when rendering. This will cause problems with the Toolkit as the files will no longer be in a disk location that it recognises. To disable this behaviour and load the scripts from their original location:

  1. In Deadline, navigate to Tools > Configure Plugin (In the super user mode)
  2. Disable the option 'Enable Path Mapping'

Render Farm Integration 2

If it's not possible to install Toolkit on the render farm then another option available is to convert Shotgun Write nodes to regular Nuke Write nodes before sending the script to be rendered.

To facilitate this, there are two methods available on the tk-nuke-writenode app, convert_to_write_nodes() and convert_from_write_nodes().

To convert all Shotgun Write nodes in your script to regular Nuke Write nodes, run:

import sgtk
eng = sgtk.platform.current_engine()
app = eng.apps["tk-nuke-writenode"]
if app:
    app.convert_to_write_nodes() 

Whilst there is a corresponding convert_from_write_nodes() function available, to ensure data integrity it is recommended that this is only used for debugging and not as part of your pipeline.

Technical Details

The following API methods are available on the App:

get_write_nodes()

Return a list of all Shotgun Write Nodes in the current scene.

list app.get_write_nodes()

Parameters & Return Value

  • Returns: list - a list of Toolkit Write nodes found in the scene

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()

get_node_name()

Return the name of the specified Write Node.

string get_node_name(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the name of the node.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_name(nodes[0])

get_node_profile_name()

Get the name of the configuration profile used by the specified Write node.

string get_node_profile_name(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the profile name for this Write Node as defined by the configuration

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_profile_name(nodes[0])

get_node_render_path()

Get the path that the specified Write node will render images to.

string get_node_render_path(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the render path for this node

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_render_path(nodes[0]) 

get_node_render_files()

Get a list of all image files that have been rendered for the specified Write Node.

list get_node_render_files(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: list - a list of the image files rendered by this Write node.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_render_files(nodes[0])

get_node_render_template()

Get the template that determines where rendered images will be written to for the specified Write Node as defined in the configuration.

template get_node_render_template(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: template - the render template this node is configured to use.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_render_template(nodes[0]) 

get_node_publish_template()

Get the template that determines where rendered images will be published to for the specified Write Node as defined in the configuration.

template get_node_publish_template(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: template - the publish template this node is configured to use.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_publish_template(nodes[0]) 

get_node_proxy_render_path()

Get the path that the specified Write node will render proxy images to.

string get_node_proxy_render_path(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the proxy render path for this node

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_proxy_render_path(nodes[0]) 

get_node_proxy_render_files()

Get a list of all proxy image files that have been rendered for the specified Write Node.

list get_node_proxy_render_files(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: list - a list of the proxy image files rendered by this Write node.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_proxy_render_files(nodes[0])

get_node_proxy_render_template()

Get the template that determines where proxy rendered images will be written to for the specified Write Node as defined in the configuration.

If there is no proxy render template configured for the specified node then this will return the regular render template instead.

template get_node_proxy_render_template(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: template - the proxy render template this node is configured to use.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_proxy_render_template(nodes[0]) 

get_node_proxy_publish_template()

Get the template that determines where proxy rendered images will be published to for the specified Write Node as defined in the configuration.

If there is no proxy publish template configured for the specified node then this will return the regular publish template instead.

template get_node_proxy_publish_template(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: template - the proxy publish template this node is configured to use.

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_proxy_publish_template(nodes[0]) 

get_node_published_file_type()

Get the Published File Type to be used when Published files are created for images rendered by the specified Write node as defined in the configuration.

string get_node_published_file_type(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the Published File Type this node is configured to use

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.get_node_published_file_type(nodes[0]) 

generate_node_thumbnail()

Generate a thumbnail for the specified Write Node. This will render a frame from the middle of the sequence with a maximum size of 800x800px to a temp file (.png). It is the responsibility of the caller to clean up this file when it is no longer needed.

string generate_node_thumbnail(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: string - the path to the rendered thumbnail image on disk

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.generate_node_thumbnail(nodes[0]) 

reset_node_render_path()

Reset the render path for the specified Write Node to match the current script.

None reset_node_render_path(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: None - no value is returned

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.reset_node_render_path(nodes[0]) 

is_node_render_path_locked()

Determine if the render path for the specified Write node is locked or not.

bool is_node_render_path_locked(node node)

Parameters & Return Value

  • node node - the Write Node to query
  • Returns: bool - True if the render path is locked, otherwise False

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> nodes = app.get_write_nodes()
>>> app.is_node_render_path_locked(nodes[0]) 

convert_to_write_nodes()

Convert all Shotgun write nodes found in the current Script to regular Nuke Write nodes. Additional toolkit information will be stored on user knobs named 'tk_*'

None convert_to_write_nodes()

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> app.convert_to_write_nodes() 

convert_from_write_nodes()

Convert all regular Nuke Write nodes that have previously been converted from Shotgun Write nodes, back into Shotgun Write nodes.

None convert_from_write_nodes()

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> app.convert_from_write_nodes() 

process_placeholder_nodes()

Convert any placeholder nodes into full Shotgun Write Nodes. This is primarily used to convert placeholder nodes created by the Hiero Toolkit script exporter when a script is first opened in Nuke.

None process_placeholder_nodes()

Example

>>> import sgtk
>>> eng = sgtk.platform.current_engine()
>>> app = eng.apps["tk-nuke-writenode"]
>>> app.process_placeholder_nodes() 
Clone this wiki locally