Skip to content

Commit

Permalink
fixed problem with pickling while saving
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Sep 22, 2024
1 parent 961fb42 commit 1c65b33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 9 additions & 6 deletions molecularnodes/entities/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, message):
class MolecularEntity(metaclass=ABCMeta):
def __init__(self) -> None:
self.uuid: str = str(uuid1())
self.object_ref: bpy.types.Object | None
self._object: bpy.types.Object | None
self.type: str = ""

@property
Expand Down Expand Up @@ -45,24 +45,27 @@ def object(self) -> bpy.types.Object | None:
# if the connection is broken then trying to the name will raise a connection
# error. If we are loading from a saved session then the object_ref will be
# None and get an AttributeError
self.object_ref.name
return self.object_ref
self._object.name
return self._object
except (ReferenceError, AttributeError):
for obj in bpy.data.objects:
if obj.mn.uuid == self.uuid:
print(
Warning(
f"Lost connection to object: {self.object_ref}, now connected to {obj}"
f"Lost connection to object: {self._object}, now connected to {obj}"
)
)
self.object_ref = obj
self._object = obj
return obj

return None

@object.setter
def object(self, value):
self.object_ref = value
if isinstance(value, bpy.types.Object) or value is None:
self._object = value
else:
raise TypeError(f"The `object` must be a Blender object, not {value=}")

def named_attribute(self, name="position", evaluate=False) -> np.ndarray | None:
"""
Expand Down
7 changes: 2 additions & 5 deletions molecularnodes/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def trim(dictionary: dict):
if hasattr(item, "calculations"):
item.calculations = {}
try:
if isinstance(item.object, bpy.types.Object):
item.name = item.object.name
item.object = None
item.object = None
if hasattr(item, "frames"):
if isinstance(item.frames, bpy.types.Collection):
item.frames_name = item.frames.name
Expand Down Expand Up @@ -131,12 +129,11 @@ def __repr__(self) -> str:
def pickle(self, filepath) -> None:
pickle_path = self.stashpath(filepath)

make_paths_relative(self.trajectories)
self.molecules = trim(self.molecules)
self.trajectories = trim(self.trajectories)
self.ensembles = trim(self.ensembles)

make_paths_relative(self.trajectories)

# don't save anything if there is nothing to save
if self.n_items == 0:
return None
Expand Down

0 comments on commit 1c65b33

Please sign in to comment.