Skip to content

Commit 44b22e8

Browse files
committed
find functions for scene objects
1 parent 2d32ec0 commit 44b22e8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `compas.scene.Scene.find_by_name` to find the first scene object with the given name.
13+
* Added `compas.scene.Scene.find_by_itemtype` to find the first scene object with a data item of the given type.
14+
1215
### Changed
1316

1417
### Removed

src/compas/scene/scene.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import compas.data # noqa: F401
12
import compas.datastructures # noqa: F401
23
import compas.geometry # noqa: F401
34
from compas.datastructures import Tree
@@ -211,3 +212,37 @@ def redraw(self):
211212

212213
self.clear(clear_scene=False, clear_context=True)
213214
self.draw()
215+
216+
def find_by_name(self, name):
217+
"""Find the first scene object with the given name.
218+
219+
Parameters
220+
----------
221+
name : str
222+
Name of the object.
223+
224+
Returns
225+
-------
226+
:class:`SceneObject`
227+
228+
"""
229+
# type: (str) -> SceneObject
230+
return self.get_node_by_name(name=name)
231+
232+
def find_by_itemtype(self, itemtype):
233+
"""Find the first scene object with a data item of the given type.
234+
235+
Parameters
236+
----------
237+
itemtype : :class:`compas.data.Data`
238+
The type of the data item associated with the scene object.
239+
240+
Returns
241+
-------
242+
:class:`SceneObject`
243+
244+
"""
245+
# type: (Type[compas.data.Data]) -> SceneObject
246+
for obj in self.objects:
247+
if isinstance(obj.item, itemtype):
248+
return obj

0 commit comments

Comments
 (0)