2
$\begingroup$

First of all, I'm new to blender scripting.

I'm looking for a way to uniquely identify an object, something that will reference the same object regardless of renames or any other changes in the scene.

I noticed that blender can give me the memory location where the object is stored and it doesn't seem to change. ('<bpy_struct, Object("Cube1") at 0x0000016BAD418108>')

Is there any way to turn this into an object that I can then use in my script?

Thank you!

$\endgroup$
1
  • $\begingroup$ Alright, so what I actually wanted to make was a mesh sequence object. I needed to have a list of references to different meshes in the sequence, but apparently I can just have a list of mesh objects(that update automatically on rename and deletion) as a custom property, so that's cool $\endgroup$
    – Michael777
    Commented Jul 8, 2022 at 6:59

1 Answer 1

1
$\begingroup$

As far as I know, the most popular way to identify the object is using custom props. The workflow is:

Register prop in add-on registration:

bpy.types.Object.myObjectID = bpy.props.StringProperty(name='My Object ID')

Use string or int, up to you.

Then use it then it's needed:

bpy.context.active_object.myObjectID = "ID 1"

or

m = bpy.data.meshes.new('MyMesh')
obj = bpy.data.objects.new("MyMesh",m)
obj.myObjectID = "ID 1"

On add-on unregister, disable prop:

bpy.props.RemoveProperty(bpy.types.Object, "myObjectID")

or

del bpy.types.Object.myObjectID 
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .