Yadle launches File Intelligence
and AI to Improve How We Work

Full width home advertisement

Post Page Advertisement [Top]



Implement Custom File Actions with Yadle Plug-in for Foundry Nuke

Yadle enables users to find what they are looking for fast. For artists and compositors, finding their desired content is only half the battle. Being able to act on the files once found offers tremendous value especially when it comes to frequently used operations.

With Yadle’s Custom File Action Menu for the Nuke plug-in, the basic framework is provided for savvy users to call their own created python scripts to help automate their workflow.

In this article we’ll begin by sharing details for getting the plug-in installed. Then, we will cover all the different parameters for tailoring actions specific to your workflow, along with a basic example of creating a File Action that loads an image sequence and automatically connects it to the Viewer.



Installing the Yadle Plug-in for Nuke
If you have not yet installed the Yadle plug-in for Nuke, you'll want to take care of that first. Your Yadle administrator will typically install the plug-in in a centralized location for everyone in your organization to access. If you are an individual, it's just as easy to install the plug-in locally on your workstation.

The plug-in is available online and built specifically for your Yadle organization. It can be downloaded as a zip or tar.gz depending on your operating system and preference. Refer to the following for installation and setup guides for each operating system:

Everything needed to start building out your own custom File Action Menu is packaged with the plug-in. Once you have successfully installed it, continue reading through the example.

How to Customize the File Action Menu
Whether the Yadle Plug-in for Nuke was installed on a centralized location for all to access, or locally on each user’s workstation, the yadle_open_option.json contains all necessary parameters for customizing the file action menu.

For details on all of the available parameters please visit the Yadle docs here.

In this example, we will create a File Action Menu with two items. One will simply read an individual file from Yadle search results into the Node Graph. The other will read an entire image sequence into Node Graph AND automatically connect to the Viewer. This is a fairly elementary example, however the intention is to demonstrate how we lay the framework to call your more intricate python scripts.

Edit the default yadle_open_option.json file as follows: (This file lives under the ../yadle/Yadle_Nuke/yadle_nuke/yadle_scripts directory)
{
    "is_open_menu": true,
    "scripts": [
        {
            "item": "Read File",
            "plugin": {
                "script": {
                    "name": "file_read.py"
                },
                "Windows": {
                    "enable": true
                },
                "Linux": {
                    "enable": true
                },
                "Darwin": {
                    "enable": true
                }
            }
        },
        {
            "item": "Read and Connect to Viewer",
            "plugin": {
                "script": {
                    "name": "read_viewer.py"
                },
                "Windows": {
                    "enable": true
                },
                "Linux": {
                    "enable": true
                },
                "Darwin": {
                    "enable": true
                }
            }
        }
    ],
    "geo_file_list": [
        ".3d",
        ".3ds",
        ".abc",
        ".ac",
        ".amf",
        ".ase",
        ".b3d",
        ".blend",
        ".bvh",
        ".cob",
        ".dae",
        ".csm",
        ".dxf",
        ".fbx",
        ".gltf",
        ".glb",
        ".hmp",
        ".ifc",
        ".lwo",
        ".lws",
        ".md2",
        ".md5mesh",
        ".mdl",
        ".ms3d",
        ".mff",
        ".obj",
        ".off",
        ".xml",
        ".ogex",
        ".ply",
        ".raw",
        ".sib",
        ".smd",
        ".stl",
        ".ter",
        ".x",
        ".x3d",
        ".zgl"
    ]
}

As you see in this json file, two items are defined for the File Action Menu. Each will have a separate python script that will be invoked when selected. The first item "Read" will call a file_read.py script, and the second item "Read and Connect to Viewer" will call a read_viewer.py script. We have set the value to "true" for the "is_open_menu" key which turns on the File Action Menu as well as for each of the operating systems so that these file action menu items will show no matter the workstation being used. The "geo_file_list" is a necessary list of extensions for 3D filetypes so that the correct ReadGeo Node is created for 3D objects.

By default, if no path is provided with the script name, the plug-in will look for the python script in the same directory as the yadle_open_option.json file. You can specify an absolute path to another location if desired. Let's examine the two python scripts we created and will be calling for the defined file action items.

file_read.py
import sys
import traceback
import platform

import nuke

def file_read(**kwargs):
    try:
        if not kwargs:
            print('ERROR: file_import custom script: not kwargs')
            return

        print('INFO: centralized script: file_read ' + str(kwargs))

        for key, value in kwargs.iteritems():
            print('%s = %s' % (key, value))

        if 'file_path' in kwargs:
            filePath = kwargs['file_path']
            readNode = nuke.createNode('Read')
            readNode['file'].fromUserText(filePath)

    except:
        print('ERROR: ' + filePath + '(' + platform.system() + ')', traceback.format_exc(), True)

read_viewer.py
import os
import sys
import traceback
import platform
import re
import difflib

import nuke

def read_sequence_viewer(**kwargs):
    try:
        if not kwargs:
            print('ERROR: file_import custom script: not kwargs')
            return

        print('INFO: centralized script: file_read ' + str(kwargs))

        for key, value in kwargs.iteritems():
            print('%s = %s' % (key, value))

        if 'file_path' in kwargs:
            filePath = kwargs['file_path']
            fileDir = os.path.dirname(filePath)
            filename = os.path.basename(filePath)

            file_pattern_list = nuke.getFileNameList(fileDir)

            for file_pattern in file_pattern_list:
                frame_range = re.findall(r"\s\d+-\d+", file_pattern)

                pattern = ' '.join(file_pattern.split(' ')[:-1])
                seq_matcher = difflib.SequenceMatcher(None, pattern, filename)
                opcodes_list = seq_matcher.get_opcodes()
                for opcodes in opcodes_list:
                    if not opcodes:
                        continue

                    (op, pattern_first, pattern_last, filename_first, filename_last) = opcodes

                    num_hash = pattern_last - pattern_first
                    if op == 'replace' and pattern[pattern_first:pattern_last] == '#' * num_hash:
                        seq_pattern = file_pattern
                        break


            readNode = nuke.createNode('Read')
            readNode.knob('file').fromUserText(os.path.join(fileDir, seq_pattern))
            nuke.connectViewer(0, readNode)

    except:
        print('ERROR: ' + filePath + '(' + platform.system() + ')', traceback.format_exc(), True)


Demo of File Action Menu
With our File Action Menu defined using the yadle_open_option.json file and creating our python scripts, we are ready to take a look at this in action. Launch Nuke, right click anywhere on the toolbar panel and select Windows > Custom > Yadle. Login with your Yadle user credentials and perform a search for #sequence to search for all image sequences of your selected File Channel. Find the sequence you want to load. Click on the Open dropdown menu, and you will see our two custom File Actions ("Read" and "Read and Connect to Viewer"). Select the latter and all frames of the image sequence will load into a Read Node and will be automatically connected to the Viewer.



Hopefully you are now able to clearly see the capability Yadle provides for streamlining your workflow. Customize to your heart's desire.

No comments:

Post a Comment

Bottom Ad [Post Page]


Join our Blog to discover new ideas, tips, cool use cases, and how to take advantage of Yadle to help you more easily and quickly find and use your files anywhere - in the Cloud and on devices