Skip to content

Commit 673292d

Browse files
wip - adding beams to reading existing doc
1 parent 71bce97 commit 673292d

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/ansys/geometry/core/designer/design.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
from ansys.geometry.core.math.point import Point3D
8181
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
8282
from ansys.geometry.core.misc.auxiliary import (
83+
get_beams_from_ids,
8384
get_bodies_from_ids,
8485
get_edges_from_ids,
8586
get_faces_from_ids,
@@ -1145,6 +1146,7 @@ def __read_existing_design(self) -> None:
11451146
bodies = get_bodies_from_ids(self, [body.id for body in result.bodies])
11461147
faces = get_faces_from_ids(self, [face.id for face in result.faces])
11471148
edges = get_edges_from_ids(self, [edge.id for edge in result.edges])
1149+
beams = get_beams_from_ids(self, [beam.id for beam in result.beams])
11481150

11491151
design_points = []
11501152
for dp in result.design_points:
@@ -1159,7 +1161,7 @@ def __read_existing_design(self) -> None:
11591161
bodies=bodies,
11601162
faces=faces,
11611163
edges=edges,
1162-
beams=[], # BEAM IMPORT NOT SUPPORTED FOR NAMED SELECTIONS
1164+
beams=beams,
11631165
design_points=design_points,
11641166
)
11651167
self._named_selections[new_ns.name] = new_ns

src/ansys/geometry/core/misc/auxiliary.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import TYPE_CHECKING, Union
2525

2626
if TYPE_CHECKING: # pragma: no cover
27+
from ansys.geometry.core.designer.beam import Beam
2728
from ansys.geometry.core.designer.body import Body
2829
from ansys.geometry.core.designer.component import Component
2930
from ansys.geometry.core.designer.design import Design
@@ -237,6 +238,30 @@ def get_edges_from_ids(design: "Design", edge_ids: list[str]) -> list["Edge"]:
237238
] # noqa: E501
238239

239240

241+
def get_beams_from_ids(design: "Design", beam_ids: list[str]) -> list["Beam"]:
242+
"""Find the ``Beam`` objects inside a ``Design`` from its ids.
243+
244+
Parameters
245+
----------
246+
design : Design
247+
Parent design for the beams.
248+
beam_ids : list[str]
249+
List of beam ids.
250+
251+
Returns
252+
-------
253+
list[Beam]
254+
List of Beam objects.
255+
256+
Notes
257+
-----
258+
This method takes a design and beam ids, and gets their corresponding ``Beam`` objects.
259+
"""
260+
return [
261+
beam for beam in design.beams if beam.id in beam_ids
262+
] # noqa: E501
263+
264+
240265
def convert_color_to_hex(
241266
color: str | tuple[float, float, float] | tuple[float, float, float, float],
242267
) -> str:

tests/integration/test_design.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,18 @@ def test_named_selection_contents(modeler: Modeler):
466466
face = box_2.faces[2]
467467
edge = box_2.edges[0]
468468

469+
circle_profile_1 = design.add_beam_circular_profile(
470+
"CircleProfile1", Quantity(10, UNITS.mm), Point3D([0, 0, 0]), UNITVECTOR3D_X, UNITVECTOR3D_Y
471+
)
472+
beam = design.create_beam(
473+
Point3D([9, 99, 999], UNITS.mm), Point3D([8, 88, 888], UNITS.mm), circle_profile_1
474+
)
475+
469476
# Create the NamedSelection
470477
ns = design.create_named_selection(
471-
"MyNamedSelection", bodies=[box, box_2], faces=[face], edges=[edge]
478+
"MyNamedSelection", bodies=[box, box_2], faces=[face], edges=[edge], beams=[beam]
472479
)
473480

474-
print(ns.bodies)
475481
# Check that the named selection has everything
476482
assert len(ns.bodies) == 2
477483
assert np.isin([box.id, box_2.id], [body.id for body in ns.bodies]).all()
@@ -482,7 +488,7 @@ def test_named_selection_contents(modeler: Modeler):
482488
assert len(ns.edges) == 1
483489
assert ns.edges[0].id == edge.id
484490

485-
assert len(ns.beams) == 0
491+
assert len(ns.beams) == 1
486492
assert len(ns.design_points) == 0
487493

488494

0 commit comments

Comments
 (0)