Python nuke.createNode() Examples

The following are 13 code examples of nuke.createNode(). 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: menu.py    From NukeToolSet with MIT License 6 votes vote down vote up
def create_tools(self, menu, type, name, command, shortcut, icon_name):
        """
        create menu tools
        :param type:
        :param menu:
        :param name:
        :param command:
        :param shortcut:
        :param icon:
        :return:
        """
        if type == "python":
            menu.addCommand(name, command, shortcut, icon=icon_name)
        elif type == "gizmo":
            menu.addCommand(name, "nuke.createNode(\"%s\")" % command, icon=icon_name)
        elif type == "toolbar":
            menu.addCommand(name, icon=icon_name) 
Example #2
Source File: __init__.py    From anima with MIT License 6 votes vote down vote up
def create_auto_crop_writer():
    """creates a write node for every selected node, and sets the autocrop flag
    to auto crop the output for fast reading
    """
    # get selected nodes and deselect them
    nodes = nuke.selectedNodes()
    [node.setSelected(False) for node in nodes]

    write_nodes = []

    for node in nodes:
        write_node = nuke.createNode('Write')
        file_path = node['file'].value()
        filename_with_number_seq, ext = os.path.splitext(file_path)
        filename, number_seq = os.path.splitext(filename_with_number_seq)

        write_node['file'].setValue(
            filename + '_auto_cropped' + number_seq + ext
        )
        write_node['channels'].setValue('all')
        write_node['autocrop'].setValue(True)
        write_node.setXpos(node.xpos() + 100)
        write_node.setYpos(node.ypos())

        # connect it to the original node
        write_node.setInput(0, node)
        write_node.setSelected(False)

        # store the write node
        write_nodes.append(write_node)

    # connect the write nodes to afanasy if afanasy exists
    try:
        afanasy = nuke.createNode('afanasy')
        for i, node in enumerate(write_nodes):
            afanasy.setInput(i, node)
    except RuntimeError:
        pass 
Example #3
Source File: lib.py    From core with MIT License 5 votes vote down vote up
def add_write_node(name, **kwarg):
    """Adding nuke write node

    Arguments:
        name (str): nuke node name
        kwarg (attrs): data for nuke knobs

    Returns:
        node (obj): nuke write node
    """
    frame_range = kwarg.get("frame_range", None)

    w = nuke.createNode(
        "Write",
        "name {}".format(name))

    w["file"].setValue(kwarg["file"])

    for k, v in kwarg.items():
        if "frame_range" in k:
            continue
        log.info([k, v])
        try:
            w[k].setValue(v)
        except KeyError as e:
            log.debug(e)
            continue

    if frame_range:
        w["use_limit"].setValue(True)
        w["first"].setValue(frame_range[0])
        w["last"].setValue(frame_range[1])

    return w 
Example #4
Source File: nodes.py    From dpa-pipe with MIT License 5 votes vote down vote up
def create_write_product_node():

    node = nuke.createNode('Write', inpanel=True)

    node_name = 'WriteProduct'
    node_inst = 1

    while nuke.exists(node_name + str(node_inst)):
        node_inst += 1

    node_name += str(node_inst)

    node.knob('name').setValue(node_name)
    node.knob('beforeRender').setValue(
        'dpa.nuke.utils.create_product_before_render()')
    node.knob('afterFrameRender').setValue(
        'dpa.nuke.utils.set_permissions_after_frame()')

    products_tab = nuke.Tab_Knob("Product")
    node.addKnob(products_tab)
    node.addKnob(nuke.EvalString_Knob('product_desc', 'description', ""))
    node.addKnob(nuke.EvalString_Knob('product_name', 'name', 
        get_default_product_name()))
    node.addKnob(nuke.EvalString_Knob('product_ver_note', 'description', ""))

    # hide the file knob
    node.knob('file_type').setValue('exr')
    node.knob('product_ver_note').setVisible(False)

# ----------------------------------------------------------------------------- 
Example #5
Source File: cryptomatte_utilities.py    From NukeToolSet with MIT License 5 votes vote down vote up
def cryptomatte_create_gizmo():
    return nuke.createNode("Cryptomatte") 
Example #6
Source File: cryptomatte_utilities.py    From NukeToolSet with MIT License 5 votes vote down vote up
def encryptomatte_create_gizmo():
    return nuke.createNode("Encryptomatte")


#############################################
# Public - cryptomatte Events
############################################# 
Example #7
Source File: CreatedPointCloud.py    From NukeToolSet with MIT License 5 votes vote down vote up
def create_node(node_name, read_data):
    label = "%s points" % (read_data["verts_count"])
    node = nuke.createNode("BakedPointCloud")
    node.knob("serializePoints").setValue("%s %s" % (read_data["total"], read_data["points"]))
    node.knob("serializeNormals").setValue("%s %s" % (read_data["total"], read_data["normals"]))
    node.knob("serializeColors").setValue("%s %s" % (read_data["total"], read_data["colors"]))
    node.knob("name").setValue(node_name)
    node.knob("label").setValue(label) 
Example #8
Source File: ListShuffle.py    From NukeToolSet with MIT License 5 votes vote down vote up
def shuffle():
    for selected_node in nuke.selectedNodes():
        if selected_node.Class() == 'Read':
            all_channels = selected_node.channels()
            all_channels = list(set([i.split('.')[0] for i in all_channels]))
            for channel in all_channels:
                shuffle_node = nuke.createNode('Shuffle', inpanel=False)
                shuffle_node['name'].setValue(channel+'_'+selected_node['name'].getValue())
                shuffle_node['in'].setValue(channel)
                shuffle_node.setInput(0, selected_node)
                shuffle_node['postage_stamp'].setValue(1) 
Example #9
Source File: menu.py    From spin_nuke_gizmos with GNU General Public License v3.0 5 votes vote down vote up
def populate_menu_recursive(tool_path, menu):
    if not tool_path.endswith(os.sep):
        tool_path += os.sep

    for root, dirs, files in os.walk(tool_path):
        category = root.replace(tool_path, '')
        # build the dynamic menus, ignoring empty dirs:
        for dir_name in natural_sort(dirs):
            if os.listdir(os.path.join(root, dir_name)) and dir_name != DEPRECATED:
                img = find_icon(root, dir_name)
                menu.addMenu(category + '/' + dir_name, icon=img)

        # stop here if we're in a deprecated menu
        if category == DEPRECATED:
            continue

        # if we have both dirs and files, add a separator
        if files and dirs:
            submenu = menu.addMenu(category)  # menu() and findItem() do not return a menu object.
            submenu.addSeparator()

        # Populate the menus
        for nuke_file in natural_sort(files):
            file_name, extension = os.path.splitext(nuke_file)
            if extension.lower() in ['.gizmo', '.so', '.nk']:
                img = find_icon(root, file_name)
                # Adding the menu command
                if extension.lower() in ['.nk']:
                    menu.addCommand(category + '/' + file_name,
                                    'nuke.nodePaste( "{}" )'.format(os.path.join(root, nuke_file)),
                                    icon=img)
                if extension.lower() in ['.gizmo', '.so']:
                    menu.addCommand(category + '/' + file_name,
                                    'nuke.createNode( "{}" )'.format(file_name),
                                    icon=img)
    return menu 
Example #10
Source File: cryptomatte_utilities.py    From Cryptomatte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cryptomatte_create_gizmo():
    return nuke.createNode("Cryptomatte") 
Example #11
Source File: cryptomatte_utilities.py    From Cryptomatte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def encryptomatte_create_gizmo():
    return nuke.createNode("Encryptomatte")


#############################################
# Public - cryptomatte Events
############################################# 
Example #12
Source File: lib.py    From core with MIT License 4 votes vote down vote up
def imprint(node, data, tab=None):
    """Store attributes with value on node

    Parse user data into Node knobs.
    Use `collections.OrderedDict` to ensure knob order.

    Args:
        node(nuke.Node): node object from Nuke
        data(dict): collection of attributes and their value

    Returns:
        None

    Examples:
        ```
        import nuke
        from avalon.nuke import lib

        node = nuke.createNode("NoOp")
        data = {
            # Regular type of attributes
            "myList": ["x", "y", "z"],
            "myBool": True,
            "myFloat": 0.1,
            "myInt": 5,

            # Creating non-default imprint type of knob
            "MyFilePath": lib.Knobby("File_Knob", "/file/path"),
            "divider": lib.Knobby("Text_Knob", ""),

            # Manual nice knob naming
            ("my_knob", "Nice Knob Name"): "some text",

            # dict type will be created as knob group
            "KnobGroup": {
                "knob1": 5,
                "knob2": "hello",
                "knob3": ["a", "b"],
            },

            # Nested dict will be created as tab group
            "TabGroup": {
                "tab1": {"count": 5},
                "tab2": {"isGood": True},
                "tab3": {"direction": ["Left", "Right"]},
            },
        }
        lib.imprint(node, data, tab="Demo")

        ```

    """
    for knob in create_knobs(data, tab):
        node.addKnob(knob) 
Example #13
Source File: nodes.py    From dpa-pipe with MIT License 4 votes vote down vote up
def create_read_sub_node():

    node = nuke.createNode('Read', inpanel=True)

    node_name = 'ReadSub'
    node_inst = 1

    while nuke.exists(node_name + str(node_inst)):
        node_inst += 1

    node_name += str(node_inst)

    node.knob('name').setValue(node_name)
    
    sub_tab = nuke.Tab_Knob("Sub")

    # make sure the product reprs are cached
    populate_sub_cache(refresh=False)

    repr_str_list = [DEFAULT_REPR_STR]
    repr_str_list.extend(sorted(PRODUCT_REPR_STR_TO_PATH.keys()))

    product_repr_select = nuke.Enumeration_Knob(
        'product_repr_select',
        'subscription',
        repr_str_list,
    )

    product_seq_select = nuke.Enumeration_Knob(
        'product_seq_select',
        'files',
        [],
    )

    nuke.callbacks.addKnobChanged(read_sub_knob_changed,
        nodeClass='Read', node=node)

    node.addKnob(sub_tab)
    node.addKnob(product_repr_select)
    node.addKnob(product_seq_select)

    # make the tab pop to front
    node['Sub'].setFlag(0) 

    read_sub_knob_changed(node=node, knob=node.knob('product_repr_select'))

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