Skip to content

pipeline

containerise(name, namespace, nodes, context, loader, suffix='_CON')

Bundle nodes into an assembly and imprint it 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
nodes list

Long names of nodes to containerise

required
context dict

Asset information

required
loader str

Name of loader used to produce this container.

required
suffix str

Suffix of container, defaults to _CON.

'_CON'

Returns:

Name Type Description
container BaseObject

OSelection BaseObject container

Source code in client/ayon_cinema4d/api/pipeline.py
191
192
193
194
195
196
197
198
199
200
201
202
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def containerise(name,
                 namespace,
                 nodes,
                 context,
                 loader,
                 suffix="_CON"):
    """Bundle `nodes` into an assembly and imprint it 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
        nodes (list): Long names of nodes to containerise
        context (dict): Asset information
        loader (str): Name of loader used to produce this container.
        suffix (str, optional): Suffix of container, defaults to `_CON`.

    Returns:
        container (c4d.BaseObject): OSelection BaseObject container

    """

    container_name = lib.get_unique_namespace(
        name,
        prefix=namespace + "_",
        suffix=suffix
    )
    with lib.undo_chunk():
        container = c4d.BaseObject(c4d.Oselection)
        container.SetName(container_name)
        in_exclude_data = container[c4d.SELECTIONOBJECT_LIST]
        for node in nodes:
            in_exclude_data.InsertObject(node, 1)
        container[c4d.SELECTIONOBJECT_LIST] = in_exclude_data
        doc = lib.active_document()
        doc.InsertObject(container)

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

        # Add the container to the AYON_CONTAINERS layer
        avalon_layer = get_containers_layer(doc=doc)
        container.SetLayerObject(avalon_layer)
        # Hide the container in the Object Manager
        # container.ChangeNBit(c4d.NBIT_OHIDE, c4d.NBITCONTROL_SET)
        c4d.EventAdd()

    return container

get_containers_layer(doc=None)

Get the layer that holds all container objects.

To make the scene less cluttered the containers (selection objects) are put in a layer 'AYON_CONTAINERS'. This layer is hidden in the outliner.

Parameters:

Name Type Description Default
doc optional c4d.documents.BaseDocument

The document to work on. If it is None it uses the active document.

None
Source code in client/ayon_cinema4d/api/pipeline.py
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
def get_containers_layer(doc=None):
    """Get the layer that holds all container objects.

    To make the scene less cluttered the containers (selection objects) are put
    in a layer 'AYON_CONTAINERS'. This layer is hidden in the outliner.

    Arguments:
        doc (optional c4d.documents.BaseDocument): The document to work on. If
            it is None it uses the active document.
    """

    doc = doc or lib.active_document()
    layer_root = doc.GetLayerObjectRoot()
    for layer in layer_root.GetChildren():
        if layer.GetName() == AYON_CONTAINERS:
            return layer

    layer = c4d.documents.LayerObject()
    layer.SetName(AYON_CONTAINERS)
    layer.InsertUnder(layer_root)
    layer[c4d.ID_LAYER_MANAGER] = False
    layer[c4d.ID_LAYER_VIEW] = False
    layer[c4d.ID_LAYER_RENDER] = False
    layer[c4d.ID_LAYER_COLOR] = c4d.Vector(0.3, 0.66, 0.96)
    layer[c4d.ID_LAYER_LOCKED] = True

    c4d.EventAdd()

    return layer

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

Imprints an object with container metadata and hides it from the user by adding it into a hidden layer. Arguments: container (c4d.BaseObject): The object to imprint. 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.

Source code in client/ayon_cinema4d/api/pipeline.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def imprint_container(
    container,
    name,
    namespace,
    context,
    loader
):
    """Imprints an object with container metadata and hides it from the user
    by adding it into a hidden layer.
    Arguments:
        container (c4d.BaseObject): The object to imprint.
        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.
    """
    data = {
        "schema": "ayon:container-3.0",
        "id": AYON_CONTAINER_ID,
        "name": name,
        "namespace": namespace,
        "loader": str(loader),
        "representation": str(context["representation"]["id"]),
    }

    lib.imprint(container, data, group="AYON")

iter_containers(doc=None)

Yield all objects in the active document that have 'id' attribute set matching an AYON container ID

Source code in client/ayon_cinema4d/api/pipeline.py
147
148
149
150
151
152
153
154
155
156
157
def iter_containers(doc=None):
    """Yield all objects in the active document that have 'id' attribute set
    matching an AYON container ID"""
    doc = doc or c4d.documents.GetActiveDocument()
    containers = lib.iter_objects(doc.GetFirstObject())
    for container in containers:
        if lib.get_object_user_data_by_name(container, "id") != AYON_CONTAINER_ID:  # noqa
            continue

        data = parse_container(container)
        yield data

parse_container(container)

Return the container node's full container data.

Parameters:

Name Type Description Default
container str

A container node name.

required

Returns:

Type Description

dict[str, Any]: The container schema data for this container node.

Source code in client/ayon_cinema4d/api/pipeline.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def parse_container(container):
    """Return the container node's full container data.

    Args:
        container (str): A container node name.

    Returns:
        dict[str, Any]: The container schema data for this container node.

    """
    data = lib.read(container)

    # Backwards compatibility pre-schemas for containers
    data["schema"] = data.get("schema", "ayon:container-3.0")

    # Append transient data
    data["objectName"] = container.GetName()
    data["node"] = container

    return data