I would like to assign a unique Immutable index of the objects that are added in the scene. I want this unique index to be stored in an object type property (Relative to the object)
Obviously the object can be deleted and I would like the index to always grow regardless of whether the object is deleted (keeping it stored somewhere)
So assuming you have 10 objects in the scene, they will have an index, from 1 to 10
Assuming deleting all 10 objects, I would like that by adding a new object, the index continues to grow, i.e. in this case the index should be 11, Obviously the index could be very high even if there are few objects in the scene, but it is very important that it remains so, and that it is always growing.
I suppose I should create a list that contains all the previous indexes or something similar.
This situation is making me difficult.
This is how we declare an object-type property:
I don't really know how to build a function that assigns correctly only when the len(bpy.data.objects[:])
changes, I can also think of a function called by bpy.app.handlers.depsgraph_update_post()
, but I'm not sure
class ObjectProperties(bpy.types.PropertyGroup):
obj_index = bpy.props.IntProperty()
def register():
bpy.types.Object.obj_prop = bpy.props.PointerProperty(type=ObjectProperties)
My question is inherent in this answer , I was thinking of indexing all the objects present in the bpy.data.objects with a unique index. I want to try replacing the "Object Info" node with a driver, which is driven by the object's IntProperty Like this:
An additional problem is when copying the object (Without instance)
I have done various tests, but there seems to be some problem with updating the integer value in the Driver.
Based on @batFINGER 's answer, the indexing method seems to be right for me. But I can't understand where I am wrong with the driver, when I assign sefl.scene_object_index to the driver, the driver never changes and always remains on 0 Although in this case C.object.scene_object_index is 6 (As seen in the console)
I had already noticed this problem, when I tried to make an index in my own way, I noticed that the driver was assuming wrong values