2727from ansys .geometry .core .connection .conversions import grpc_point_to_point3d
2828from ansys .geometry .core .designer .beam import Beam
2929from ansys .geometry .core .designer .body import Body
30+ from ansys .geometry .core .designer .component import Component
3031from ansys .geometry .core .designer .designpoint import DesignPoint
3132from ansys .geometry .core .designer .edge import Edge
3233from ansys .geometry .core .designer .face import Face
3334from ansys .geometry .core .misc .auxiliary import (
3435 get_beams_from_ids ,
3536 get_bodies_from_ids ,
37+ get_components_from_ids ,
3638 get_edges_from_ids ,
3739 get_faces_from_ids ,
3840)
@@ -67,6 +69,8 @@ class NamedSelection:
6769 All beams to include in the named selection.
6870 design_points : list[DesignPoints], default: None
6971 All design points to include in the named selection.
72+ components: list[Component], default: None
73+ All components to include in the named selection.
7074 """
7175
7276 def __init__ (
@@ -79,6 +83,7 @@ def __init__(
7983 edges : list [Edge ] | None = None ,
8084 beams : list [Beam ] | None = None ,
8185 design_points : list [DesignPoint ] | None = None ,
86+ components : list [Component ] | None = None ,
8287 preexisting_id : str | None = None ,
8388 ):
8489 """Initialize the ``NamedSelection`` class."""
@@ -97,13 +102,16 @@ def __init__(
97102 beams = []
98103 if design_points is None :
99104 design_points = []
105+ if components is None :
106+ components = []
100107
101108 # Instantiate
102109 self ._bodies = bodies
103110 self ._faces = faces
104111 self ._edges = edges
105112 self ._beams = beams
106113 self ._design_points = design_points
114+ self ._components = components
107115
108116 # Store ids for later use... when verifying if the NS changed.
109117 self ._ids_cached = {
@@ -112,6 +120,7 @@ def __init__(
112120 "edges" : [edge .id for edge in edges ],
113121 "beams" : [beam .id for beam in beams ],
114122 "design_points" : [dp .id for dp in design_points ],
123+ "components" : [component .id for component in components ],
115124 }
116125
117126 if preexisting_id :
@@ -194,6 +203,22 @@ def design_points(self) -> list[DesignPoint]:
194203
195204 return self ._design_points
196205
206+ @property
207+ def components (self ) -> list [Component ]:
208+ """All components in the named selection."""
209+ self .__verify_ns ()
210+ if self ._grpc_client .backend_version < (26 , 1 , 0 ):
211+ self ._grpc_client .log .warning (
212+ "Accessing components in named selections is only"
213+ " consistent starting in version 2026 R1."
214+ )
215+ return []
216+ if self ._components is None :
217+ # Get all components from the named selection
218+ self ._components = get_components_from_ids (self ._design , self ._ids_cached ["components" ])
219+
220+ return self ._components
221+
197222 def __verify_ns (self ) -> None :
198223 """Verify that the contents of the named selection are up to date."""
199224 if self ._grpc_client .backend_version < (25 , 2 , 0 ):
@@ -213,6 +238,7 @@ def __verify_ns(self) -> None:
213238 "edges" : response .get ("edges" ),
214239 "beams" : response .get ("beams" ),
215240 "design_points" : response .get ("design_points" ),
241+ "components" : response .get ("components" ),
216242 }
217243
218244 for key in ids :
@@ -232,4 +258,5 @@ def __repr__(self) -> str:
232258 lines .append (f" N Edges : { len (self .edges )} " )
233259 lines .append (f" N Beams : { len (self .beams )} " )
234260 lines .append (f" N Design Points : { len (self .design_points )} " )
261+ lines .append (f" N Components : { len (self .components )} " )
235262 return "\n " .join (lines )
0 commit comments