Skip to content

workfile_template_builder

NukePlaceholderPlugin

Bases: PlaceholderPlugin

Source code in client/ayon_nuke/api/workfile_template_builder.py
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
class NukePlaceholderPlugin(PlaceholderPlugin):
    node_color = 4278190335

    def _collect_scene_placeholders(self):
        # Cache placeholder data to shared data
        placeholder_nodes = self.builder.get_shared_populate_data(
            "placeholder_nodes"
        )
        if placeholder_nodes is None:
            placeholder_nodes = {}
            all_groups = collections.deque()
            all_groups.append(nuke.thisGroup())
            while all_groups:
                group = all_groups.popleft()
                for node in group.nodes():
                    if isinstance(node, nuke.Group):
                        all_groups.append(node)

                    node_knobs = node.knobs()
                    if (
                        "is_placeholder" not in node_knobs
                        or not node.knob("is_placeholder").value()
                    ):
                        continue

                    if "empty" in node_knobs and node.knob("empty").value():
                        continue

                    placeholder_nodes[node.fullName()] = node

            self.builder.set_shared_populate_data(
                "placeholder_nodes", placeholder_nodes
            )
        return placeholder_nodes

    def create_placeholder(self, placeholder_data):
        placeholder_data["plugin_identifier"] = self.identifier

        placeholder = nuke.nodes.NoOp()
        placeholder.setName("PLACEHOLDER")
        placeholder.knob("tile_color").setValue(self.node_color)

        imprint(placeholder, placeholder_data)
        imprint(placeholder, {"is_placeholder": True})
        placeholder.knob("is_placeholder").setVisible(False)

    def update_placeholder(self, placeholder_item, placeholder_data):
        node = nuke.toNode(placeholder_item.scene_identifier)
        imprint(node, placeholder_data)

    def _parse_placeholder_node_data(self, node):
        placeholder_data = {}
        for key in self.get_placeholder_keys():
            knob = node.knob(key)
            value = None
            if knob is not None:
                value = knob.getValue()
            placeholder_data[key] = value
        return placeholder_data

    def delete_placeholder(self, placeholder):
        """Remove placeholder if building was successful"""
        placeholder_node = nuke.toNode(placeholder.scene_identifier)
        nuke.delete(placeholder_node)

delete_placeholder(placeholder)

Remove placeholder if building was successful

Source code in client/ayon_nuke/api/workfile_template_builder.py
105
106
107
108
def delete_placeholder(self, placeholder):
    """Remove placeholder if building was successful"""
    placeholder_node = nuke.toNode(placeholder.scene_identifier)
    nuke.delete(placeholder_node)

NukeTemplateBuilder

Bases: AbstractTemplateBuilder

Concrete implementation of AbstractTemplateBuilder for nuke

Source code in client/ayon_nuke/api/workfile_template_builder.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class NukeTemplateBuilder(AbstractTemplateBuilder):
    """Concrete implementation of AbstractTemplateBuilder for nuke"""

    def import_template(self, path):
        """Import template into current scene.
        Block if a template is already loaded.

        Args:
            path (str): A path to current template (usually given by
            get_template_preset implementation)

        Returns:
            bool: Whether the template was successfully imported or not
        """

        # TODO check if the template is already imported

        nuke.nodePaste(path)
        reset_selection()

        return True

import_template(path)

Import template into current scene. Block if a template is already loaded.

Parameters:

Name Type Description Default
path str

A path to current template (usually given by

required

Returns:

Name Type Description
bool

Whether the template was successfully imported or not

Source code in client/ayon_nuke/api/workfile_template_builder.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def import_template(self, path):
    """Import template into current scene.
    Block if a template is already loaded.

    Args:
        path (str): A path to current template (usually given by
        get_template_preset implementation)

    Returns:
        bool: Whether the template was successfully imported or not
    """

    # TODO check if the template is already imported

    nuke.nodePaste(path)
    reset_selection()

    return True