Hello I am still new to Blender and learned Python 2 weeks ago. (I have previous experience in C)
I found a good example for creating a Custom list for objects on here and it works splendidly.
however in my Addon i have a function that removes certain objects that are also in the list. When this happens it will leave an empty row in the custom list. To remove it i need the index number of the object. Displayed in the code below
scn = context.scene idx = scn.custom_index scn.custom_index -= 1 scn.custom.remove(idx)
however i do not know how to get the index of this object when i only have access to it's name to also remove it in the custom list
below is the code for the list:
class CUSTOM_UL_items(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): obj = item.obj custom_icon = "OUTLINER_OB_EMPTY" row = layout.row() #split.label(text="Index: %d" % (index)) row.prop(obj, "name", text='', emboss=False, translate=False, icon=custom_icon) def invoke(self, context, event): pass class CUSTOM_PG_objectCollection(PropertyGroup): #name: StringProperty() -> Instantiated by default obj: PointerProperty( name="Object", type=bpy.types.Object) classes = ( CUSTOM_UL_items, CUSTOM_PG_objectCollection, ) def register(): from . import custom_props, custom_ui from bpy.utils import register_class for cls in classes: register_class(cls) # Custom scene properties bpy.types.Scene.custom = CollectionProperty(type=CUSTOM_PG_objectCollection) bpy.types.Scene.custom_index = IntProperty() def unregister(): from . import custom_props, custom_ui from bpy.utils import unregister_class for cls in reversed(classes): unregister_class(cls) del bpy.types.Scene.custom del bpy.types.Scene.custom_index
The way i know how to get the custom_index right now is by selecting it in the custom list and using
If anyone knows how to access the index of specific items in the list by using it's name then i will appreciate it. i will provide an image showing the list with a removed item so you can see more clearly what i mean.