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}")
def fit_aos(target: T.bpy_prop_collection, proxy: AosProxy, context: Context): """ Adjust the size of a bpy_prop_collection proxified as an array of structures (e.g. MeshVertices) """ if not hasattr(target, "bl_rna"): return target_rna = target.bl_rna 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 if isinstance(target_rna, type(T.SplineBezierPoints.bl_rna)): existing_length = len(target) incoming_length = proxy.length delta = incoming_length - existing_length if delta > 0: target.add(delta) else: logger.error("Remove not implemented for type SplineBezierPoints") return logger.error( f"Not implemented fit_aos for type {target.bl_rna} for {target} ...")
def _truncate_collection_pop(collection: T.bpy_prop_collection, size: int): while len(collection) > max(size, 0): collection.pop()