Skip to content

pipeline

Pipeline tools for Ayon Substance Designer integration.

get_instances()

Return all instances stored in the project instances as a list

Source code in client/ayon_substancedesigner/api/pipeline.py
298
299
300
301
302
303
304
305
306
def get_instances():
    """Return all instances stored in the project instances as a list"""
    current_package = get_package_from_current_graph()
    if not current_package:
        return []

    get_instances_by_id = parsing_sd_data(
        current_package, AYON_METADATA_INSTANCES_KEY) or {}
    return list(get_instances_by_id.values())

imprint(current_package, name, namespace, context, loader, identifier, options=None)

Imprint a loaded container with metadata.

Containerisation enables a tracking of version, author and origin for loaded assets.

Parameters:

Name Type Description Default
name str

Name of resulting assembly

required
namespace str

Namespace under which to host container

required
context dict

Asset information

required
loader LoaderPlugin

loader instance used to produce container.

required
identifier(str)

SDResource identifier

required
options(dict)

options

required

Returns:

Type Description

None

Source code in client/ayon_substancedesigner/api/pipeline.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def imprint(current_package, name, namespace, context,
            loader, identifier, options=None):
    """Imprint a loaded container with metadata.

    Containerisation enables a tracking of version, author and origin
    for loaded assets.

    Arguments:
        name (str): Name of resulting assembly
        namespace (str): Namespace under which to host container
        context (dict): Asset information
        loader (load.LoaderPlugin): loader instance used to produce container.
        identifier(str): SDResource identifier
        options(dict): options

    Returns:
        None

    """
    data = {
        "schema": "ayon:container-2.0",
        "id": AVALON_CONTAINER_ID,
        "name": str(name),
        "namespace": str(namespace) if namespace else None,
        "loader": str(loader.__class__.__name__),
        "representation": context["representation"]["id"],
        "project_name": context["project"]["name"],
        "objectName": identifier
    }
    if options:
        for key, value in options.items():
            data[key] = value
    container_data = parsing_sd_data(
        current_package, AYON_METADATA_CONTAINERS_KEY, is_dictionary=False)
    container_data.append(data)
    set_sd_metadata(AYON_METADATA_CONTAINERS_KEY, container_data)

remove_container_metadata(container)

Helper method to remove the data for a specific container

Source code in client/ayon_substancedesigner/api/pipeline.py
244
245
246
247
248
249
250
251
252
253
def remove_container_metadata(container):
    """Helper method to remove the data for a specific container"""
    current_package = get_package_from_current_graph()
    all_container_metadata = parsing_sd_data(
        current_package, AYON_METADATA_CONTAINERS_KEY, is_dictionary=False)
    metadata_remainder = [
        container_data for container_data in all_container_metadata
        if container_data["objectName"] != container["objectName"]
    ]
    set_sd_metadata(AYON_METADATA_CONTAINERS_KEY, metadata_remainder)

remove_instance(instance_id)

Helper method to remove the data for a specific container

Source code in client/ayon_substancedesigner/api/pipeline.py
288
289
290
291
292
293
294
295
def remove_instance(instance_id):
    """Helper method to remove the data for a specific container"""
    current_package = get_package_from_current_graph()
    if current_package:
        instances = parsing_sd_data(
            current_package, AYON_METADATA_INSTANCES_KEY) or {}
        instances.pop(instance_id, None)
        set_sd_metadata(AYON_METADATA_INSTANCES_KEY, instances)

set_instance(instance_id, instance_data, update=False)

Helper method to directly set the data for a specific container

Parameters:

Name Type Description Default
instance_id str

Unique identifier for the instance

required
instance_data dict

The instance data to store in the metaadata.

required
Source code in client/ayon_substancedesigner/api/pipeline.py
256
257
258
259
260
261
262
263
def set_instance(instance_id, instance_data, update=False):
    """Helper method to directly set the data for a specific container

    Args:
        instance_id (str): Unique identifier for the instance
        instance_data (dict): The instance data to store in the metaadata.
    """
    set_instances({instance_id: instance_data}, update=update)

set_instances(instance_data_by_id, update=False)

Store data for multiple instances at the same time.

Parameters:

Name Type Description Default
instance_data_by_id dict

instance data queried by id

required
update bool

whether the data needs update. Defaults to False.

False
Source code in client/ayon_substancedesigner/api/pipeline.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def set_instances(instance_data_by_id, update=False):
    """Store data for multiple instances at the same time.

    Args:
        instance_data_by_id (dict): instance data queried by id
        update (bool, optional): whether the data needs update.
            Defaults to False.
    """
    current_package = get_package_from_current_graph()
    if current_package:
        instances = parsing_sd_data(
            current_package, AYON_METADATA_INSTANCES_KEY) or {}
        for instance_id, instance_data in instance_data_by_id.items():
            if update:
                existing_data = instances.get(instance_id, {})
                existing_data.update(instance_data)
            else:
                instances[instance_id] = instance_data

        set_sd_metadata(AYON_METADATA_INSTANCES_KEY, instances)