1
$\begingroup$

I have tried print(context.active_object.name_full), but that seems to be just the object name that I see in the Outliner. If I change the name in the Outliner, then name_full changes, too.

Is there any unique and invariable ID to identify an object at least within the session? That is, the unique ID should not be changed even if the user changes the object's name. The ID does not have to be same if the user opens the file again next time.

$\endgroup$
1
2
$\begingroup$

Use a pointer property

Can set up a pointer to any blender ID type objects, in this case bpy.types.Object instances of which can be found in bpy.data.objects collection.

Assign the property to class

import bpy
from bpy.types import Object, Scene
from bpy.props import PointerProperty


Scene.target_obj = PointerProperty(type=Object)

Test.

>>> C.object
bpy.data.objects['Cube']

>>> bpy.ops.object.duplicate()
{'FINISHED'}

>>> C.object
bpy.data.objects['Cube.001']

>>> C.scene.target_obj = C.object
>>> C.object.name = "Foo"
>>> C.scene.target_obj
bpy.data.objects['Foo']
$\endgroup$
3
  • $\begingroup$ So this provides a unique way of IDing an object in a scene as long as the scene and object exist in that file? The pointer doesn't change or anything after the file is saved, closed, and reloaded, right? $\endgroup$
    – Tango
    Apr 5 at 5:53
  • $\begingroup$ Once set it is a reference to that object, or None if the object is since removed. $\endgroup$
    – batFINGER
    Apr 5 at 5:57
  • $\begingroup$ Thank you - I was all set to generate a UUID for objects, since I know they can be renamed and wanted some handle to be sure I was always using the same object. $\endgroup$
    – Tango
    Apr 5 at 6:02
0
$\begingroup$

It depends on what you need it for. You could set object.pass_index to unique number, or you could create your own custom property:

enter image description here

Or do it with Python: object[some_custom_property] = "Some value"

$\endgroup$
1
  • $\begingroup$ if you copy the object the copy will have same pass index and same custom property. $\endgroup$
    – batFINGER
    Jun 22 '20 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.