Skip to content

Commit

Permalink
find functions for scene objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Sep 9, 2024
1 parent 2d32ec0 commit 44b22e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `compas.scene.Scene.find_by_name` to find the first scene object with the given name.
* Added `compas.scene.Scene.find_by_itemtype` to find the first scene object with a data item of the given type.

### Changed

### Removed
Expand Down
35 changes: 35 additions & 0 deletions src/compas/scene/scene.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import compas.data # noqa: F401
import compas.datastructures # noqa: F401
import compas.geometry # noqa: F401
from compas.datastructures import Tree
Expand Down Expand Up @@ -211,3 +212,37 @@ def redraw(self):

self.clear(clear_scene=False, clear_context=True)
self.draw()

def find_by_name(self, name):
"""Find the first scene object with the given name.
Parameters
----------
name : str
Name of the object.
Returns
-------
:class:`SceneObject`
"""
# type: (str) -> SceneObject
return self.get_node_by_name(name=name)

def find_by_itemtype(self, itemtype):
"""Find the first scene object with a data item of the given type.
Parameters
----------
itemtype : :class:`compas.data.Data`
The type of the data item associated with the scene object.
Returns
-------
:class:`SceneObject`
"""
# type: (Type[compas.data.Data]) -> SceneObject
for obj in self.objects:
if isinstance(obj.item, itemtype):
return obj

0 comments on commit 44b22e8

Please sign in to comment.