Skip to content

pipeline

get_container_nodes()

Return a list of node names that are marked as loaded container.

Source code in client/ayon_openrv/api/pipeline.py
231
232
233
234
235
236
237
238
def get_container_nodes():
    """Return a list of node names that are marked as loaded container."""
    container_nodes = []
    for node in rv.commands.nodes():
        prop = f"{node}.{OPENPYPE_ATTR_PREFIX}schema"
        if rv.commands.propertyExists(prop):
            container_nodes.append(node)
    return container_nodes

get_containers()

Yield container data for each container found in current workfile.

Source code in client/ayon_openrv/api/pipeline.py
241
242
243
244
245
246
def get_containers():
    """Yield container data for each container found in current workfile."""
    for node in get_container_nodes():
        container = parse_container(node)
        if container:
            yield container

imprint(node, data, prefix=None)

Store attributes with value on a node.

Parameters:

Name Type Description Default
node object

The node to imprint data on.

required
data dict

Key value pairs of attributes to create.

required
prefix str

A prefix to add to all keys in the data.

None

Returns:

Type Description

None

Source code in client/ayon_openrv/api/pipeline.py
 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
def imprint(node, data, prefix=None):
    """Store attributes with value on a node.

    Args:
        node (object): The node to imprint data on.
        data (dict): Key value pairs of attributes to create.
        prefix (str): A prefix to add to all keys in the data.

    Returns:
        None

    """
    node_prefix = f"{node}.{prefix}" if prefix else f"{node}."
    for attr, value in data.items():
        # Create and set the attribute
        prop = f"{node_prefix}.{attr}"

        if isinstance(value, (dict, list, tuple)):
            value = f"{JSON_PREFIX}{json.dumps(value)}"

        if isinstance(value, (bool, int)):
            type_name = "Int"
        elif isinstance(value, float):
            type_name = "Float"
        elif isinstance(value, str):
            type_name = "String"
        else:
            raise TypeError("Unsupport data type to imprint: "
                            "{} (type: {})".format(value, type(value)))

        if not rv.commands.propertyExists(prop):
            type_ = getattr(rv.commands, f"{type_name}Type")
            rv.commands.newProperty(prop, type_, 1)
        set_property = getattr(rv.commands, f"set{type_name}Property")
        set_property(prop, [value], True)

imprint_container(node, name, namespace, context, loader)

Imprint node with container metadata.

Parameters:

Name Type Description Default
node object

The node to containerise.

required
name str

Name of resulting assembly

required
namespace str

Namespace under which to host container

required
context dict

Asset information

required
loader str

Name of loader used to produce this container.

required

Returns:

Type Description

None

Source code in client/ayon_openrv/api/pipeline.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
def imprint_container(node, name, namespace, context, loader):
    """Imprint `node` with container metadata.

    Arguments:
        node (object): The node to containerise.
        name (str): Name of resulting assembly
        namespace (str): Namespace under which to host container
        context (dict): Asset information
        loader (str): Name of loader used to produce this container.

    Returns:
        None

    """

    data = [
        ("schema", "openpype:container-2.0"),
        ("id", str(AVALON_CONTAINER_ID)),
        ("name", str(name)),
        ("namespace", str(namespace)),
        ("loader", str(loader)),
        ("representation", str(context["representation"]["id"]))
    ]

    # We use an OrderedDict to make sure the attributes
    # are always created in the same order. This is solely
    # to make debugging easier when reading the values in
    # the attribute editor.
    imprint(node, OrderedDict(data), prefix=OPENPYPE_ATTR_PREFIX)

parse_container(node)

Returns imprinted container data of a tool

This reads the imprinted data from imprint_container.

Source code in client/ayon_openrv/api/pipeline.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
def parse_container(node):
    """Returns imprinted container data of a tool

    This reads the imprinted data from `imprint_container`.

    """
    # If not all required data return None
    required = ['id', 'schema', 'name',
                'namespace', 'loader', 'representation']

    data = {}
    for key in required:
        prop = f"{node}.{OPENPYPE_ATTR_PREFIX}{key}"
        if not rv.commands.propertyExists(prop):
            return

        value = rv.commands.getStringProperty(prop)[0]
        data[key] = value

    # Store the node's name
    data["objectName"] = str(node)

    # Store reference to the node object
    data["node"] = node

    return data

read(node, prefix=None)

Read properties from the given node with the values

This function assumes all read values are of a single width and will return only the first entry. As such, arrays or multidimensional properties will not be returned correctly.

Parameters:

Name Type Description Default
node str

Name of node.

required
prefix str

A prefix for the attributes to consider. This prefix will be stripped from the output key.

None

Returns:

Name Type Description
dict

The key, value of the properties.

Source code in client/ayon_openrv/api/pipeline.py
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
def read(node, prefix=None):
    """Read properties from the given node with the values

    This function assumes all read values are of a single width and will
    return only the first entry. As such, arrays or multidimensional properties
    will not be returned correctly.

    Args:
        node (str): Name of node.
        prefix (str, optional): A prefix for the attributes to consider.
            This prefix will be stripped from the output key.

    Returns:
        dict: The key, value of the properties.

    """
    properties = rv.commands.properties(node)
    node_prefix = f"{node}.{prefix}" if prefix else f"{node}."
    type_getters = {
        1: rv.commands.getFloatProperty,
        2: rv.commands.getIntProperty,
        # Not sure why 3, 4 and 5 don't seem to be types
        5: rv.commands.getHalfProperty,
        6: rv.commands.getByteProperty,
        8: rv.commands.getStringProperty
    }

    data = {}
    for prop in properties:
        if prefix is not None and not prop.startswith(node_prefix):
            continue

        info = rv.commands.propertyInfo(prop)
        type_num = info["type"]
        value = type_getters[type_num](prop)
        if value:
            value = value[0]
        else:
            value = None

        if type_num == 8 and value and value.strip().startswith(JSON_PREFIX):
            # String
            value = json.loads(value.strip()[len(JSON_PREFIX):])

        key = prop[len(node_prefix):]
        data[key] = value

    return data