Esempio n. 1
0
    def process(self):
        self.name = self.data["subset"]

        instance = nuke.toNode(self.data["subset"])

        family = self.family
        node = 'write'

        if not instance:
            write_data = {
                "class": node,
                "preset": self.preset,
                "avalon": self.data
            }

            create_write_node(self.data["subset"], write_data)

        return
Esempio n. 2
0
    def process(self):
        self.name = self.data["subset"]

        instance = nuke.toNode(self.data["subset"])

        family = self.family
        node = 'write'

        if not instance:
            write_data = {
                "frame_range": [nuke.frame(), nuke.frame()],
                "class": node,
                "preset": self.preset,
                "avalon": self.data
            }

            nuke.createNode("FrameHold", "first_frame {}".format(nuke.frame()))
            create_write_node(self.data["subset"], write_data)

        return
Esempio n. 3
0
    def process(self):
        from pype.nuke import lib as pnlib
        reload(pnlib)

        inputs = []
        outputs = []
        instance = nuke.toNode(self.data["subset"])
        selected_node = None

        # use selection
        if (self.options or {}).get("useSelection"):
            nodes = nuke.selectedNodes()

            assert len(nodes) == 1, self.log.error(
                "Select only one node. The node you want to connect to, or tick off `Use selection`"
            )

            selected_node = nodes[0]
            inputs = [selected_node]
            outputs = selected_node.dependent()

            if instance:
                if (instance.name() in selected_node.name()):
                    selected_node = instance.dependencies()[0]

        # if node already exist
        if instance:
            # collect input / outputs
            inputs = instance.dependencies()
            outputs = instance.dependent()
            selected_node = inputs[0]
            # remove old one
            nuke.delete(instance)

        # recreate new
        write_data = {
            "class": self.nClass,
            "families": [self.family],
            "avalon": self.data
        }

        if self.presets.get('fpath_template'):
            self.log.info("Adding template path from preset")
            write_data.update(
                {"fpath_template": self.presets["fpath_template"]})
        else:
            self.log.info("Adding template path from plugin")
            write_data.update({
                "fpath_template":
                "{work}/renders/nuke/{subset}/{subset}.{frame}.{ext}"
            })

        write_node = pnlib.create_write_node(self.data["subset"],
                                             write_data,
                                             input=selected_node)

        # relinking to collected connections
        for i, input in enumerate(inputs):
            write_node.setInput(i, input)

        write_node.autoplace()

        for output in outputs:
            output.setInput(0, write_node)

        return True
Esempio n. 4
0
def create_write_node(name, data, input=None, prenodes=None):
    ''' Creating write node which is group node

    Arguments:
        name (str): name of node
        data (dict): data to be imprinted
        input (node): selected node to connect to
        prenodes (list, optional): list of lists, definitions for nodes
                                to be created before write

    Example:
        prenodes = [(
            "NameNode",  # string
            "NodeClass",  # string
            (   # OrderDict: knob and values pairs
                ("knobName", "knobValue"),
                ("knobName", "knobValue")
            ),
            (   # list outputs
                "firstPostNodeName",
                "secondPostNodeName"
            )
        )
        ]

    Return:
        node (obj): group node with avalon data as Knobs
    '''

    nuke_dataflow_writes = get_node_dataflow_preset(**data)
    nuke_colorspace_writes = get_node_colorspace_preset(**data)
    application = lib.get_application(os.environ["AVALON_APP_NAME"])

    try:
        data.update({
            "application": application,
            "nuke_dataflow_writes": nuke_dataflow_writes,
            "nuke_colorspace_writes": nuke_colorspace_writes
        })
        anatomy_filled = format_anatomy(data)

    except Exception as e:
        log.error("problem with resolving anatomy tepmlate: {}".format(e))

    # build file path to workfiles
    fpath = str(anatomy_filled["work"]["folder"]).replace("\\", "/")
    fpath = data["fpath_template"].format(
        work=fpath,
        version=data["version"],
        subset=data["subset"],
        frame=data["frame"],
        ext=data["nuke_dataflow_writes"]["file_type"])

    # create directory
    if not os.path.isdir(os.path.dirname(fpath)):
        log.warning("Path does not exist! I am creating it.")
        os.makedirs(os.path.dirname(fpath), 0o766)

    _data = OrderedDict({"file": fpath})

    # adding dataflow template
    log.debug("nuke_dataflow_writes: `{}`".format(nuke_dataflow_writes))
    {
        _data.update({k: v})
        for k, v in nuke_dataflow_writes.items()
        if k not in ["_id", "_previous"]
    }

    # adding colorspace template
    log.debug("nuke_colorspace_writes: `{}`".format(nuke_colorspace_writes))
    {_data.update({k: v}) for k, v in nuke_colorspace_writes.items()}

    _data = avalon.nuke.lib.fix_data_for_node_create(_data)

    log.debug("_data: `{}`".format(_data))

    if "frame_range" in data.keys():
        _data["frame_range"] = data.get("frame_range", None)
        log.debug("_data[frame_range]: `{}`".format(_data["frame_range"]))

    GN = nuke.createNode("Group", "name {}".format(name))

    prev_node = None
    with GN:
        connections = list()
        if input:
            # if connected input node was defined
            connections.append({"node": input, "inputName": input.name()})
            prev_node = nuke.createNode("Input",
                                        "name {}".format(input.name()))
        else:
            # generic input node connected to nothing
            prev_node = nuke.createNode("Input", "name {}".format("rgba"))

        # creating pre-write nodes `prenodes`
        if prenodes:
            for name, klass, properties, set_output_to in prenodes:
                # create node
                now_node = nuke.createNode(klass, "name {}".format(name))

                # add data to knob
                for k, v in properties:
                    if k and v:
                        now_node[k].serValue(str(v))

                # connect to previous node
                if set_output_to:
                    if isinstance(set_output_to, (tuple or list)):
                        for i, node_name in enumerate(set_output_to):
                            input_node = nuke.createNode(
                                "Input", "name {}".format(node_name))
                            connections.append({
                                "node": nuke.toNode(node_name),
                                "inputName": node_name
                            })
                            now_node.setInput(1, input_node)
                    elif isinstance(set_output_to, str):
                        input_node = nuke.createNode(
                            "Input", "name {}".format(node_name))
                        connections.append({
                            "node": nuke.toNode(set_output_to),
                            "inputName": set_output_to
                        })
                        now_node.setInput(0, input_node)
                else:
                    now_node.setInput(0, prev_node)

                # swith actual node to previous
                prev_node = now_node

        # creating write node
        write_node = now_node = avalon.nuke.lib.add_write_node(
            "inside_{}".format(name), **_data)

        # connect to previous node
        now_node.setInput(0, prev_node)

        # swith actual node to previous
        prev_node = now_node

        now_node = nuke.createNode("Output", "name Output1")

        # connect to previous node
        now_node.setInput(0, prev_node)

    # imprinting group node
    GN = avalon.nuke.imprint(GN, data["avalon"])

    divider = nuke.Text_Knob('')
    GN.addKnob(divider)

    add_rendering_knobs(GN)

    # adding write to read button
    add_button_write_to_read(GN)

    divider = nuke.Text_Knob('')
    GN.addKnob(divider)

    # set tile color
    tile_color = _data.get("tile_color", "0xff0000ff")
    GN["tile_color"].setValue(tile_color)

    # add render button
    lnk = nuke.Link_Knob("Render")
    lnk.makeLink(write_node.name(), "Render")
    lnk.setName("Render")
    GN.addKnob(lnk)

    # Deadline tab.
    add_deadline_tab(GN)

    return GN