From 5707bcc21e9ba6ef40d0e46a063bbcab5e945e34 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:53:10 +0100 Subject: [PATCH 1/2] feat: adding __len__ to components --- src/ansys/mapdl/core/component.py | 10 ++++++++++ tests/test_component.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ansys/mapdl/core/component.py b/src/ansys/mapdl/core/component.py index 402f229338..4bd35df8b7 100644 --- a/src/ansys/mapdl/core/component.py +++ b/src/ansys/mapdl/core/component.py @@ -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]: """ diff --git a/tests/test_component.py b/tests/test_component.py index aa790c4ff7..38c093fa82 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -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) From 8335e0c711e99f04df2b62061dadb9bf57ffe727 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:11:05 +0000 Subject: [PATCH 2/2] chore: adding changelog file 3663.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3663.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3663.miscellaneous.md diff --git a/doc/changelog.d/3663.miscellaneous.md b/doc/changelog.d/3663.miscellaneous.md new file mode 100644 index 0000000000..1765d3ae2a --- /dev/null +++ b/doc/changelog.d/3663.miscellaneous.md @@ -0,0 +1 @@ +feat: adding __len__ to components \ No newline at end of file