Here is my issue : I would like to add a unique Int property on an object.
This property needs to be unique even when duplicated. So according to Duplicating object and default value of property and https://blenderartists.org/forum/showthread.php?328009-Unique-object-id I did this :
# Getter for anchor duplicate def get_global_index(self): # print("getting value") done = False # get current index index = self.global_index #Recursive ?! # chek if already used (in case of a duplicate) and try a new one while necessary while not done: anchors = [obj for obj in bpy.context.scene.objects if obj.type == 'EMPTY' and obj.empty_draw_type == 'PLAIN_AXES'] # already referenced if any(obj.global_index == self.global_index for obj in anchors): # found to try another index print("Trying another index") index = context.scene.global_index context.scene.global_index+=1 else: done = True print("FOUND index") return index def register(): bpy.types.Object.list_index = bpy.props.IntProperty(name = "Index for my_list", default = 0) #Each anchor needs a unique index bpy.types.Scene.global_index = bpy.props.IntProperty(name = "Global index for Anchors", default = 0) #So use scene index to store the increment bpy.types.Object.global_index = bpy.props.IntProperty(name = "Object index for Anchors", default = 0, get=get_global_index)
BUT, The getter seems to loop infinitely and I don't understand what I'm doing wrong. I just want the getter to check in the current objects of the specified king to check if the index is not already used (when Duplicated) because I need to have each one of them having a unique index.