Skip to content

Commit b3c1172

Browse files
feat: adding __len__ to components (#3663)
* feat: adding __len__ to components * chore: adding changelog file 3663.miscellaneous.md [dependabot-skip] --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 61fa744 commit b3c1172

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

doc/changelog.d/3663.miscellaneous.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: adding __len__ to components

src/ansys/mapdl/core/component.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ def __iter__(self) -> Iterator:
471471
"""
472472
yield from self._comp.keys()
473473

474+
def __len__(self) -> int:
475+
"""Return the number of components
476+
477+
Returns
478+
-------
479+
int
480+
Number of components
481+
"""
482+
return self._comp.__len__()
483+
474484
@property
475485
def names(self) -> Tuple[str]:
476486
"""

tests/test_component.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,12 @@ def test_dunder_methods_items(mapdl, basic_components):
383383
assert [("MYCOMP1", "NODE"), ("MYCOMP2", "KP")] == list(
384384
mapdl.components.items()
385385
)
386+
387+
@staticmethod
388+
def test_dunder_methods_len(mapdl, basic_components):
389+
assert len(mapdl.components) == 2
390+
mapdl.components["mycomp3"] = "NODE", [1, 2]
391+
assert len(mapdl.components) == 3
392+
mapdl.nsel("s", vmin=1)
393+
mapdl.cm("asdf", "node")
394+
assert len(mapdl.components) == 4

0 commit comments

Comments
 (0)