def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: node = context.visit_state.attribute(-1) if not isinstance(node, _node_groups): logger.warning( f"Unexpected add node input for {node} at {context.visit_path.path()}" ) socket_type = proxy.data("bl_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: node_type = proxy.data("bl_idname") try: return collection.new(node_type) except RuntimeError as e: name = proxy.data("name") logger.error( f"add_element failed for node {name!r} into {context.visit_state.display_path()} ..." ) logger.error(f"... {e!r}") raise AddElementFailed from None
def _add_element_sequence(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): type_name = proxy.data("type") name = proxy.data("name") channel = proxy.data("channel") frame_start = proxy.data("frame_start") if type_name in _effect_sequences: # overwritten anyway frame_end = frame_start + 1 return collection.new_effect(name, type_name, channel, frame_start, frame_end=frame_end) if type_name == "SOUND": sound = proxy.data("sound") target = sound.target(context) 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_name == "MOVIE": filepath = proxy.data("filepath") return collection.new_movie(name, filepath, channel, frame_start) if type_name == "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_name}") return None
def _add_element_default(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): 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 {collection} ...") return None try: return new_or_add() except TypeError: try: key = proxy.data("name") 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
def _add_element_default(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: try: new_or_add = collection.new except AttributeError: try: new_or_add = collection.add except AttributeError: logger.error( f"add_element: not implemented for {context.visit_state.display_path()} ..." ) raise AddElementFailed from None try: return new_or_add() except TypeError: try: key = proxy.data("name") return new_or_add(key) except Exception as e: logger.error( f"add_element: not implemented for {context.visit_state.display_path()} ..." ) logger.error(f"... {e!r}") raise AddElementFailed from None
def _add_element_keyingset(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): # TODO current implementation fails # All keying sets paths have an empty name, and insertion with add() fails # with an empty name target_ref = proxy.data("id") if target_ref is None: target = None else: target = target_ref.target(context) 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)
def _add_element_type_name(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): socket_type = proxy.data("type") name = proxy.data("name") return collection.new(socket_type, name)
def _add_element_name_eq(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): name = proxy.data("name") return collection.new(name=name)
def _add_element_frame_number(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): frame_number = proxy.data("frame_number") return collection.new(frame_number)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: frame_number = proxy.data("frame_number") return collection.new(frame_number)
def _add_element_location(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): location = proxy.data("location") return collection.new(location[0], location[1])
def _add_element_material_ref(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): material_datablock = proxy.target(context) return collection.append(material_datablock)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: name = proxy.data("info") return collection.new(name)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: location = proxy.data("location") return collection.new(location[0], location[1])
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: type_ = proxy.data("type") return collection.new(type=type_)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: socket_type = proxy.data("type") name = proxy.data("name") return collection.new(socket_type, name)
def _add_element_name_type(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): name = proxy.data("name") type_ = proxy.data("type") return collection.new(name, type_)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: label = proxy.data("bl_label") idname = proxy.data("bl_idname") return collection.new(name=label, idname=idname)
def _add_element_type_eq(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): type_ = proxy.data("type") return collection.new(type=type_)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: data_path = proxy.data("data_path") array_index = proxy.data("array_index") return collection.new(data_path, index=array_index)
def _add_element_idname(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): node_type = proxy.data("bl_idname") return collection.new(node_type)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: material_datablock = proxy.target(context) return collection.append(material_datablock)
def _add_element_info(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): name = proxy.data("info") return collection.new(name)
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: name = proxy.data("name") type_ = proxy.data("type") domain = proxy.data("domain") return collection.new(name, type_, domain)
def _add_element_bl_label(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): label = proxy.data("bl_label") idname = proxy.data("bl_idname") return collection.new(name=label, idname=idname)
def add_element(proxy: Proxy, collection: T.bpy_prop_collection, key: str, context: Context): """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.ObjectModifiers.bl_rna), type(T.ObjectGpencilModifiers.bl_rna))): name = proxy.data("name") modifier_type = proxy.data("type") return collection.new(name, modifier_type) if isinstance(bl_rna, type(T.SequenceModifiers.bl_rna)): name = proxy.data("name") type_ = proxy.data("type") return collection.new(name, type_) if isinstance(bl_rna, type(T.ObjectConstraints.bl_rna)): type_ = proxy.data("type") return collection.new(type_) if isinstance(bl_rna, type(T.Nodes.bl_rna)): node_type = proxy.data("bl_idname") return collection.new(node_type) if isinstance(bl_rna, _new_name_types): name = proxy.data("name") return collection.new(name=name) if isinstance(bl_rna, type(T.GreasePencilLayers.bl_rna)): name = proxy.data("info") return collection.new(name) 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() fails # with an empty name target_ref = proxy.data("id") if target_ref is None: target = None else: target = target_ref.target(context) 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.NodeInputs.bl_rna), type(T.NodeOutputs.bl_rna), type(T.NodeTreeInputs.bl_rna), type(T.NodeTreeOutputs.bl_rna), ), ): socket_type = proxy.data("type") name = proxy.data("name") return collection.new(socket_type, name) 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(context) 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 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
def _(collection: T.bpy_prop_collection, proxy: Proxy, index: int, context: Context) -> T.bpy_struct: position = proxy.data("position") return collection.new(position)
def _add_element_position(collection: T.bpy_prop_collection, proxy: Proxy, context: Context): position = proxy.data("position") return collection.new(position)