Skip to content

Commit

Permalink
Fixes #725
Browse files Browse the repository at this point in the history
- Delete session entries for objects that no longer exist in Blender
  • Loading branch information
PardhavMaradani authored and BradyAJohnston committed Feb 10, 2025
1 parent c3b88ee commit be06432
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions molecularnodes/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _selection_update_trajectories(self, context: bpy.types.Context) -> None:
def update_entities(scene):
"Call the `set_frame()` method of all entities in the current session"
session = scene.MNSession
session.prune()
for entity in session.entities.values():
# use the updated method if it exists but otherwise fallback on the old method
# of updating the trajectories
Expand Down
12 changes: 11 additions & 1 deletion molecularnodes/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bpy.app.handlers import persistent
from bpy.props import StringProperty
from bpy.types import Context
from databpy.object import get_from_uuid
from databpy.object import get_from_uuid, LinkedObjectError

from .entities.ensemble.base import Ensemble
from .entities.molecule.molecule import Molecule
Expand Down Expand Up @@ -92,6 +92,16 @@ def get_object(self, uuid: str) -> bpy.types.Object | None:
def get(self, uuid: str) -> Union[Molecule, Trajectory, Ensemble] | None:
return self.entities.get(uuid)

def prune(self) -> None:
"""
Remove any entities that no longer exist in Blender
"""
for uuid in list(self.entities):
try:
_ = self.entities[uuid].name
except LinkedObjectError:
del self.entities[uuid]

@property
def n_items(self) -> int:
"The number of items being tracked by this session."
Expand Down

0 comments on commit be06432

Please sign in to comment.