@Kilon
Hi!
Thank you for all these precisions. Itâs interesting to know what really happens when creating a value in python. But just to be clear, I never assumed that my_property value would update when ob.name changes in:
my_object['my_property'] = ob.name
In fact, this is precisely the problem I was exposing.
This is a temporary solution and I know that this will be a bug in my addon if it stays like that.
What I would need, is a reference to the object itself and not its name. This would work. Unfortunatly, there is no ID property that can store a reference to an object in the API, as I understand it. At least, this is a part of my question.
And if you can help me on that, it would be very appreciated. (I see that the mirror modifier can store a reference to an object in the mirror_object property)
Since the ID properties can only store basic values such as int, float, and string; the object itself cannot be referenced directly. But there could be an indirect way if there was a unique ID for each objects. Then, this unique ID could be saved as a string in the ID property and accessed back by using this unique ID.
In the API, each objects have an id_data. For example, the id_data of my_object could be <bpy_struct, Object(âMonkeyâ)>. This could be stored in the property as a string. But the only significant information it contains, is that it is an âobjectâ which is named âmy_objectâ. The problem with the id_data is that it is only unique at a precise moment. The id_data changes as the object name changes. And another object could take its name, and take the place of the first id_data. So id_data are not unique.
For example: Looking for a unique ID, I found that it is possible to get the address of an object by doing :
address = my_object.as_pointer()
The address will be represented as an int which can easily be stored in an ID property. The object can be retrieved by traversing bpy.data.objects. (Maybe there is a more direct way but I donât know it) The problem with the address, is that the object will most certainly not occupy the same memory addres when reloading the .blend file.
So here are my questions :
- Is there a way to create with the python API a property like MirrorModifier.mirror_object which points to a specific object?
- Is there a truly Unique ID for each objects which remains the same even if the name of the object has changed?
Any help is very appreciated.