Skip to content

Commit

Permalink
fix uuid mismatch when wrapping obj (#11)
Browse files Browse the repository at this point in the history
* fix uuid mismatch when wrapping obj

* also for string lookup

* fix register for building docs

* test for registering the uuid
  • Loading branch information
BradyAJohnston authored Jan 7, 2025
1 parent ba02e36 commit c0f0509
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 9 additions & 1 deletion databpy/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,18 @@ def __init__(self, obj: Object | str | None = None):
self._uuid: str = str(uuid1())
self._object_name: str = ""

if not hasattr(bpy.types.Object, "uuid"):
register()

if isinstance(obj, Object):
if obj.uuid != "":
self._uuid = obj.uuid
self.object = obj
elif isinstance(obj, str):
self.object = bpy.data.objects[obj]
obj = bpy.data.objects[obj]
if obj.uuid != "":
self._uuid = obj.uuid
self.object = obj
elif obj is None:
self._object_name = ""

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "databpy"
version = "0.0.6"
version = "0.0.7"
description = "A data-oriented wrapper library for the Blender Python API"
readme = "README.md"
dependencies = ["numpy>=1.26.0,<2.0"]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ def test_bob(snapshot):
assert not np.allclose(pos_a, pos_b)
assert snapshot == pos_a
assert snapshot == pos_b


# test that we aren't overwriting an existing UUID on an object, when wrapping it with
# with BlenderObject
def test_bob_mismatch_uuid():
bob = db.BlenderObject(bpy.data.objects["Cube"])
obj = bob.object
old_uuid = obj.uuid
bob = db.BlenderObject(obj)
assert old_uuid == bob.uuid


def test_register():
db.unregister()
bob = db.BlenderObject(bpy.data.objects["Cube"])
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0f0509

Please sign in to comment.