def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: socket_type = proxy.data("bl_socket_idname") name = proxy.data("name") return collection.new(socket_type, name)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: name = proxy.data("name") type_ = proxy.data("type") return collection.new(name, type_)
def add_element(proxy: Proxy, collection: T.bpy_prop_collection, key: str): """Add an element to a bpy_prop_collection using the collection specific API """ bl_rna = getattr(collection, "bl_rna", None) if bl_rna is not None: if isinstance(bl_rna, type(T.KeyingSets.bl_rna)): idname = proxy.data("bl_idname") return collection.new(name=key, idname=idname) if isinstance(bl_rna, type(T.KeyingSetPaths.bl_rna)): # TODO current implementation fails # All keying sets paths have an empty name, and insertion with add()à failes # with an empty name target_ref = proxy.data("id") if target_ref is None: target = None else: target = target_ref.target() data_path = proxy.data("data_path") index = proxy.data("array_index") group_method = proxy.data("group_method") group_name = proxy.data("group") return collection.add(target_id=target, data_path=data_path, index=index, group_method=group_method, group_name=group_name) if isinstance(bl_rna, type(T.Nodes.bl_rna)): node_type = proxy.data("bl_idname") return collection.new(node_type) if isinstance(bl_rna, type(T.Sequences.bl_rna)): type_ = proxy.data("type") name = proxy.data("name") channel = proxy.data("channel") frame_start = proxy.data("frame_start") if type_ in effect_sequences: # overwritten anyway frame_end = frame_start + 1 return collection.new_effect(name, type_, channel, frame_start, frame_end=frame_end) if type_ == "SOUND": sound = proxy.data("sound") target = sound.target() if not target: logger.warning( f"missing target ID block for bpy.data.{sound.collection}[{sound.key}] " ) return None filepath = target.filepath return collection.new_sound(name, filepath, channel, frame_start) if type_ == "MOVIE": filepath = proxy.data("filepath") return collection.new_movie(name, filepath, channel, frame_start) if type_ == "IMAGE": directory = proxy.data("directory") filename = proxy.data("elements").data(0).data("filename") filepath = str(Path(directory) / filename) return collection.new_image(name, filepath, channel, frame_start) logger.warning(f"Sequence type not implemented: {type_}") # SCENE may be harder than it seems, since we cannot order scene creations. # Currently the creation order is the "deepmost" order as listed in proxy.py:_creation_order # but it does not work for this case return None if isinstance(bl_rna, type(T.SequenceModifiers.bl_rna)): name = proxy.data("name") type_ = proxy.data("type") return collection.new(name, type_) try: return collection.add() except Exception: pass # try our best new_or_add = getattr(collection, "new", None) if new_or_add is None: new_or_add = getattr(collection, "add", None) if new_or_add is None: logger.warning( f"Not implemented new or add for bpy.data.{collection}[{key}] ...") return None try: return new_or_add(key) except Exception: logger.warning( f"Not implemented new or add for type {type(collection)} for {collection}[{key}] ..." ) for s in traceback.format_exc().splitlines(): logger.warning(f"...{s}") return None