Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding __len__ to components #3663

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/3663.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: adding __len__ to components
10 changes: 10 additions & 0 deletions src/ansys/mapdl/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ def __iter__(self) -> Iterator:
"""
yield from self._comp.keys()

def __len__(self) -> int:
"""Return the number of components

Returns
-------
int
Number of components
"""
return self._comp.__len__()

@property
def names(self) -> Tuple[str]:
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ def test_dunder_methods_items(mapdl, basic_components):
assert [("MYCOMP1", "NODE"), ("MYCOMP2", "KP")] == list(mapdl.components.items())


def test_dunder_methods_len(mapdl, basic_components):
assert len(mapdl.components) == 2
mapdl.components["mycomp3"] = "NODE", [1, 2]
assert len(mapdl.components) == 3
mapdl.nsel("s", vmin=1)
mapdl.cm("asdf", "node")
assert len(mapdl.components) == 4


def test__get_all_components_type(mapdl, cube_geom_and_mesh):
mapdl.allsel()
mapdl.esel("s", "", "", 1)
Expand Down
Loading