Skip to content

load_gizmo

LoadGizmo

Bases: LoaderPlugin

Loading nuke Gizmo

Source code in client/ayon_nuke/plugins/load/load_gizmo.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
class LoadGizmo(load.LoaderPlugin):
    """Loading nuke Gizmo"""

    product_types = {"gizmo", "lensDistortion"}
    representations = {"*"}
    extensions = {"nk"}

    settings_category = "nuke"

    label = "Load Gizmo"
    order = 0
    icon = "dropbox"
    color = "white"
    node_color = "0x75338eff"

    def load(self, context, name, namespace, data):
        """
        Loading function to get Gizmo into node graph

        Arguments:
            context (dict): context of version
            name (str): name of the version
            namespace (str): namespace name
            data (dict): compulsory attribute > not used

        Returns:
            nuke node: containerized nuke node object
        """

        # get main variables
        version_entity = context["version"]
        version_attributes = version_entity["attrib"]

        first = version_attributes.get("frameStart")
        last = version_attributes.get("frameEnd")
        colorspace = version_attributes.get("colorSpace")

        namespace = namespace or context["folder"]["name"]
        object_name = "{}_{}".format(name, namespace)

        # prepare data for imprinting
        data_imprint = {
            "frameStart": first,
            "frameEnd": last,
            "version": version_entity["version"],
            "colorspaceInput": colorspace
        }

        # add attributes from the version to imprint to metadata knob
        for k in [
            "frameStart",
            "frameEnd",
            "handleStart",
            "handleEnd",
            "source",
            "fps"
        ]:
            data_imprint[k] = version_attributes[k]

        # getting file path
        file = self.filepath_from_context(context).replace("\\", "/")

        # adding nodes to node graph
        # just in case we are in group lets jump out of it
        nuke.endGroup()

        with maintained_selection():
            # add group from nk
            nuke.nodePaste(file)

            group_node = nuke.selectedNode()

            group_node["name"].setValue(object_name)

            return containerise(
                node=group_node,
                name=name,
                namespace=namespace,
                context=context,
                loader=self.__class__.__name__,
                data=data_imprint)

    def update(self, container, context):
        """Update the Loader's path

        Nuke automatically tries to reset some variables when changing
        the loader's path to a new file. These automatic changes are to its
        inputs:

        """

        # get main variables
        # Get version from io
        project_name = context["project"]["name"]
        version_entity = context["version"]
        repre_entity = context["representation"]

        version_attributes = version_entity["attrib"]

        # get corresponding node
        group_node = container["node"]

        file = get_representation_path(repre_entity).replace("\\", "/")

        first = version_attributes.get("frameStart")
        last = version_attributes.get("frameEnd")
        colorspace = version_attributes.get("colorSpace")

        data_imprint = {
            "representation": repre_entity["id"],
            "frameStart": first,
            "frameEnd": last,
            "version": version_entity["version"],
            "colorspaceInput": colorspace
        }

        for k in [
            "frameStart",
            "frameEnd",
            "handleStart",
            "handleEnd",
            "source",
            "fps"
        ]:
            data_imprint[k] = version_attributes[k]

        # capture pipeline metadata
        avalon_data = get_avalon_knob_data(group_node)

        # adding nodes to node graph
        # just in case we are in group lets jump out of it
        nuke.endGroup()

        with maintained_selection([group_node]):
            # insert nuke script to the script
            nuke.nodePaste(file)
            # convert imported to selected node
            new_group_node = nuke.selectedNode()
            # swap nodes with maintained connections
            with swap_node_with_dependency(
                    group_node, new_group_node) as node_name:
                new_group_node["name"].setValue(node_name)
                # set updated pipeline metadata
                set_avalon_knob_data(new_group_node, avalon_data)

        last_version_entity = ayon_api.get_last_version_by_product_id(
            project_name, version_entity["productId"], fields={"id"}
        )

        # change color of node
        if version_entity["id"] == last_version_entity["id"]:
            color_value = self.node_color
        else:
            color_value = "0xd88467ff"

        new_group_node["tile_color"].setValue(int(color_value, 16))

        self.log.info(
            "updated to version: {}".format(version_entity["name"])
        )

        return update_container(new_group_node, data_imprint)

    def switch(self, container, context):
        self.update(container, context)

    def remove(self, container):
        node = container["node"]
        with viewer_update_and_undo_stop():
            nuke.delete(node)

load(context, name, namespace, data)

Loading function to get Gizmo into node graph

Parameters:

Name Type Description Default
context dict

context of version

required
name str

name of the version

required
namespace str

namespace name

required
data dict

compulsory attribute > not used

required

Returns:

Type Description

nuke node: containerized nuke node object

Source code in client/ayon_nuke/plugins/load/load_gizmo.py
 36
 37
 38
 39
 40
 41
 42
 43
 44
 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
def load(self, context, name, namespace, data):
    """
    Loading function to get Gizmo into node graph

    Arguments:
        context (dict): context of version
        name (str): name of the version
        namespace (str): namespace name
        data (dict): compulsory attribute > not used

    Returns:
        nuke node: containerized nuke node object
    """

    # get main variables
    version_entity = context["version"]
    version_attributes = version_entity["attrib"]

    first = version_attributes.get("frameStart")
    last = version_attributes.get("frameEnd")
    colorspace = version_attributes.get("colorSpace")

    namespace = namespace or context["folder"]["name"]
    object_name = "{}_{}".format(name, namespace)

    # prepare data for imprinting
    data_imprint = {
        "frameStart": first,
        "frameEnd": last,
        "version": version_entity["version"],
        "colorspaceInput": colorspace
    }

    # add attributes from the version to imprint to metadata knob
    for k in [
        "frameStart",
        "frameEnd",
        "handleStart",
        "handleEnd",
        "source",
        "fps"
    ]:
        data_imprint[k] = version_attributes[k]

    # getting file path
    file = self.filepath_from_context(context).replace("\\", "/")

    # adding nodes to node graph
    # just in case we are in group lets jump out of it
    nuke.endGroup()

    with maintained_selection():
        # add group from nk
        nuke.nodePaste(file)

        group_node = nuke.selectedNode()

        group_node["name"].setValue(object_name)

        return containerise(
            node=group_node,
            name=name,
            namespace=namespace,
            context=context,
            loader=self.__class__.__name__,
            data=data_imprint)

update(container, context)

Update the Loader's path

Nuke automatically tries to reset some variables when changing the loader's path to a new file. These automatic changes are to its inputs:

Source code in client/ayon_nuke/plugins/load/load_gizmo.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def update(self, container, context):
    """Update the Loader's path

    Nuke automatically tries to reset some variables when changing
    the loader's path to a new file. These automatic changes are to its
    inputs:

    """

    # get main variables
    # Get version from io
    project_name = context["project"]["name"]
    version_entity = context["version"]
    repre_entity = context["representation"]

    version_attributes = version_entity["attrib"]

    # get corresponding node
    group_node = container["node"]

    file = get_representation_path(repre_entity).replace("\\", "/")

    first = version_attributes.get("frameStart")
    last = version_attributes.get("frameEnd")
    colorspace = version_attributes.get("colorSpace")

    data_imprint = {
        "representation": repre_entity["id"],
        "frameStart": first,
        "frameEnd": last,
        "version": version_entity["version"],
        "colorspaceInput": colorspace
    }

    for k in [
        "frameStart",
        "frameEnd",
        "handleStart",
        "handleEnd",
        "source",
        "fps"
    ]:
        data_imprint[k] = version_attributes[k]

    # capture pipeline metadata
    avalon_data = get_avalon_knob_data(group_node)

    # adding nodes to node graph
    # just in case we are in group lets jump out of it
    nuke.endGroup()

    with maintained_selection([group_node]):
        # insert nuke script to the script
        nuke.nodePaste(file)
        # convert imported to selected node
        new_group_node = nuke.selectedNode()
        # swap nodes with maintained connections
        with swap_node_with_dependency(
                group_node, new_group_node) as node_name:
            new_group_node["name"].setValue(node_name)
            # set updated pipeline metadata
            set_avalon_knob_data(new_group_node, avalon_data)

    last_version_entity = ayon_api.get_last_version_by_product_id(
        project_name, version_entity["productId"], fields={"id"}
    )

    # change color of node
    if version_entity["id"] == last_version_entity["id"]:
        color_value = self.node_color
    else:
        color_value = "0xd88467ff"

    new_group_node["tile_color"].setValue(int(color_value, 16))

    self.log.info(
        "updated to version: {}".format(version_entity["name"])
    )

    return update_container(new_group_node, data_imprint)