Пример #1
0
def truncate_collection(target: T.bpy_prop_collection,
                        proxy: Union[StructCollectionProxy,
                                     AosProxy], context: Context):
    """"""
    if not hasattr(target, "bl_rna"):
        return

    target_rna = target.bl_rna
    if any(isinstance(target_rna, t) for t in always_clear):
        target.clear()
        return

    if isinstance(target_rna, _resize_geometry_types):
        existing_length = len(target)
        incoming_length = proxy.length
        if existing_length != incoming_length:
            if existing_length != 0:
                logger.error(f"resize_geometry(): size mismatch for {target}")
                logger.error(
                    f"... existing: {existing_length} incoming {incoming_length}"
                )
                return
            logger.debug(
                f"resizing geometry: add({incoming_length}) for {target}")
            target.add(incoming_length)
        return

    if isinstance(target_rna, type(T.GPencilStrokePoints.bl_rna)):
        existing_length = len(target)
        incoming_length = proxy.length
        delta = incoming_length - existing_length
        if delta > 0:
            target.add(delta)
        else:
            while delta < 0:
                target.pop()
                delta += 1
        return

    incoming_keys = set(proxy._data.keys())
    existing_keys = set(target.keys())
    truncate_keys = existing_keys - incoming_keys
    if not truncate_keys:
        return
    if isinstance(target_rna, type(T.KeyingSets.bl_rna)):
        for k in truncate_keys:
            target.active_index = target.find(k)
            bpy.ops.anim.keying_set_remove()
    else:
        try:
            for k in truncate_keys:
                target.remove(target[k])
        except Exception:
            logger.warning(
                f"Not implemented truncate_collection for type {target.bl_rna} for {target} ..."
            )
            for s in traceback.format_exc().splitlines():
                logger.warning(f"...{s}")
Пример #2
0
def remove_datablock(collection: T.bpy_prop_collection, datablock: T.ID):
    """Delete a datablock from its bpy.data collection"""
    if isinstance(datablock, T.Scene):
        from mixer.blender_client.scene import delete_scene

        delete_scene(datablock)
    elif isinstance(datablock, T.Key):
        # the doc labels it unsafe, use sparingly
        bpy.data.batch_remove([datablock])
    elif isinstance(datablock, T.Library):
        # TODO 2.91 has BlendDatalibraries.remove()
        logger.warning(f"remove_datablock({datablock}): ignored (library)")
    else:
        collection.remove(datablock)