Python nuke.thisNode() Examples

The following are 11 code examples of nuke.thisNode(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module nuke , or try the search function .
Example #1
Source File: validate_writegeo_node.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_expected_value(self, instance):
        import os

        expected = (
            "[python {nuke.script_directory()}]/workspace/[python "
            "{os.path.splitext(os.path.basename(nuke.scriptName()))[0]}]_"
            "[python {nuke.thisNode().name()}]"
        )

        # Extension, defaulting to exr files.
        current = self.get_current_value(instance)
        ext = os.path.splitext(os.path.basename(current))[1]
        if not ext:
            ext = ".abc"
        expected += ext

        return expected 
Example #2
Source File: cryptomatte_utilities_tests.py    From Cryptomatte with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_bug_still_exists(self):
        """Tests this bug still exists. We don't want to be running the fix if we don't have to. """
        import nuke

        if nuke.NUKE_VERSION_MAJOR == 7:  # but is known not to exist in version 7.
            return

        def test_callback(node=None, knob=None):
            node.metadata()

        callback = lambda: test_callback(nuke.thisNode())
        nuke.addKnobChanged(callback, nodeClass='Cryptomatte')

        try:
            self.test_paste_with_channelmerge()
            exception = None
        except Exception, e:
            exception = e 
Example #3
Source File: cryptomatte_utilities.py    From Cryptomatte with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def encryptomatte_add_manifest_id():
    node = nuke.thisNode()
    parent = nuke.thisParent()
    name = parent.knob('matteName').value()
    id_hex = parent.knob('idHex').value()
    manifest_key = parent.knob('manifestKey').value()
    metadata = node.metadata()
    manifest = metadata.get(manifest_key + 'manifest', "{}")

    # Add another item, with closing bracket
    last_item = '"%s":"%s"}' % (name, id_hex)
    last_bracket_pos = manifest.rfind('}')
    existing_items = manifest[:last_bracket_pos].rstrip()
    if not existing_items.endswith(',') and not existing_items.endswith('{'):
        existing_items += ','
    existing_items += last_item
    return existing_items


#############################################
# Utils - Troubleshooting
############################################# 
Example #4
Source File: utils.py    From dpa-pipe with MIT License 5 votes vote down vote up
def set_permissions_after_frame():

    node = nuke.thisNode()
    frame_path = nuke.filename(node, nuke.REPLACE)
    os.chmod(frame_path, 0660) 
Example #5
Source File: validate_write_node.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_expected_value(self, instance):
        import os

        expected = (
            "[python {nuke.script_directory()}]/workspace/[python "
            "{nuke.thisNode().name()}]/[python {os.path.splitext("
            "os.path.basename(nuke.scriptName()))[0]}]/[python {"
            "os.path.splitext(os.path.basename(nuke.scriptName()))[0]}]_"
            "[python {nuke.thisNode().name()}]"
        )

        # Default padding starting at 4 digits.
        padding = 4
        if instance.data["collection"]:
            padding = instance.data["collection"].padding
        # Can't have less than 4 digits.
        if padding < 4:
            padding = 4

        # Extension, defaulting to exr files.
        current = self.get_current_value(instance)
        ext = os.path.splitext(os.path.basename(current))[1]
        if not ext:
            ext = ".exr"

        expected += ".%{1}d{2}".format(
            instance[0].name(),
            str(padding).zfill(2),
            ext
        )
        return expected 
Example #6
Source File: cryptomatte_utilities.py    From NukeToolSet with MIT License 5 votes vote down vote up
def setup_cryptomatte():
    nuke.addKnobChanged(lambda: cryptomatte_knob_changed_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Cryptomatte')
    nuke.addKnobChanged(lambda: encryptomatte_knob_changed_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Encryptomatte')
    nuke.addOnCreate(lambda: encryptomatte_on_create_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Encryptomatte')


#############################################
# Hash to float
############################################# 
Example #7
Source File: cryptomatte_utilities.py    From NukeToolSet with MIT License 5 votes vote down vote up
def encryptomatte_add_manifest_id(deserialize = False):

    node = nuke.thisNode()
    parent = nuke.thisParent()
    name = parent.knob('matteName').value()
    id_hex = parent.knob('idHex').value()
    manifest_key = parent.knob('manifestKey').value()
    metadata = node.metadata()
    manifest = metadata.get(manifest_key + 'manifest', "{}")

    if deserialize:
        import json
        d = json.loads(manifest)
        d[name] = hex_id
        new_manifest = json.dumps(d)
        return new_manifest
    else:
        last_item = '"{name}":"{id_hex}"'.format(name=name, id_hex=id_hex)
        last_item += '}'

        last_bracket_pos = manifest.rfind('}')
        existing_items = manifest[:last_bracket_pos].rstrip()
        if not existing_items.endswith(',') and not existing_items.endswith('{'):
            return existing_items + ',' + last_item
        else:
            return existing_items + last_item


#############################################
# Utils - Unload Manifest
############################################# 
Example #8
Source File: spin_tools_callbacks.py    From spin_nuke_gizmos with GNU General Public License v3.0 5 votes vote down vote up
def center_chromatik():
    try:
        node_format = nuke.selectedNode()
    except ValueError:
        node_format = nuke.root()['format'].value()
    nuke.thisNode()['center'].setValue((node_format.width() / 2, node_format.height() / 2)) 
Example #9
Source File: __init__.py    From anima with MIT License 5 votes vote down vote up
def output_to_h264(write_node=None):
    """an after render function which converts the input to h264
    """
    # get the file name
    if not write_node:
        write_node = nuke.thisNode()

    file_full_path = nuke.filename(write_node)

    # add the _h264 extension to the filename
    file_name = os.path.basename(file_full_path)
    path = file_full_path[:-len(file_name)]
    file_name_wo_ext, ext = os.path.splitext(file_name)

    # split any '.' (ex: a.%04d -> [a, %04d])
    file_name_wo_ext = file_name_wo_ext.split('.')[0]
    # add _h264
    output_file_name = file_name_wo_ext + '_h264.mov'
    output_full_path = os.path.join(path, output_file_name)

    # TODO: if it is a sequence of images rename them by creating temp soft
    #       links to each frame and then use the sequence format in ffmpeg

    # run ffmpeg in a separate thread
    t = threading.Timer(
        1.0,
        convert_to_h264,
        args=[file_full_path, output_full_path]
    )
    t.start() 
Example #10
Source File: cryptomatte_utilities.py    From Cryptomatte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setup_cryptomatte():
    nuke.addOnCreate(lambda: cryptomatte_on_create_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Cryptomatte')
    nuke.addKnobChanged(lambda: cryptomatte_knob_changed_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Cryptomatte')
    nuke.addKnobChanged(lambda: encryptomatte_knob_changed_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Encryptomatte')
    nuke.addOnCreate(lambda: encryptomatte_on_create_event(
        nuke.thisNode(), nuke.thisKnob()), nodeClass='Encryptomatte')


#############################################
# Testing
############################################# 
Example #11
Source File: nodes.py    From dpa-pipe with MIT License 4 votes vote down vote up
def read_sub_knob_changed(node=None, knob=None):

    if not node:
        node = nuke.thisNode()

    if not knob:
        knob = nuke.thisKnob()

    if knob.name() == 'product_repr_select':
        product_repr_str = node['product_repr_select'].value()

        if (product_repr_str == DEFAULT_REPR_STR or 
            product_repr_str not in PRODUCT_REPR_STR_TO_PATH):
            node['product_seq_select'].setValues([])
            node['file'].setValue('')
            return

        repr_dir = PRODUCT_REPR_STR_TO_PATH[product_repr_str]

        # populate the possible file names
        file_specs = {}
        frame_regex = re.compile('([,\w]+).(\d{4})\.(\w+)')
        for file_name in os.listdir(repr_dir):
            
            matches = frame_regex.search(file_name)
            if matches:
                (file_base, frame_num, file_ext) = matches.groups()
                spec = file_base + '.####.' + file_ext
                file_specs[spec] = None

        file_specs = sorted(file_specs.keys())
        node['product_seq_select'].setValues(file_specs)

        file_str = os.path.join(repr_dir, file_specs[0]) 
        node['file'].setValue(file_str)

    if knob.name() == 'product_seq_select':
        
        repr_dir = os.path.dirname(node['file'].value())
        file_spec = node['product_seq_select'].value()

        file_str = os.path.join(repr_dir, file_spec)
        
        node['file'].setValue(file_str)

# -----------------------------------------------------------------------------