diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index 4fbc01c472..4f19eef4b9 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -1871,6 +1871,13 @@ def __enter__(self) -> None: self._parent().show("PNG", mute=True) self._parent().gfile(self._pixel_res, mute=True) + def __exit__(self, *args) -> None: + self._parent()._log.debug("Exiting in 'WithInterativePlotting' mode") + self._parent().show("close", mute=True) + if not self._parent()._png_mode: + self._parent().show("PNG", mute=True) + self._parent().gfile(self._pixel_res, mute=True) + def __exit__(self, *args) -> None: self._parent()._log.debug("Exiting in 'WithInterativePlotting' mode") self._parent().show("close", mute=True) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 0b8d376fc0..6f1ec7decc 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -567,3 +567,29 @@ def test_vsel_iterable(mapdl, make_block): assert np.allclose( mapdl.vsel("S", "volu", "", [1, 2, 4], "", ""), np.array([1, 2, 4]) ) + + +def test_WithInterativePlotting(mapdl, make_block): + mapdl.eplot(vtk=False) + jobname = mapdl.jobname.upper() + + def filtering(file_name): + file_name = file_name.upper() + if file_name.startswith(jobname) and file_name.endswith(".PNG"): + return True + else: + return False + + list_files = sorted([each for each in mapdl.list_files() if filtering(each)]) + last_png = list_files[0] + + if mapdl.is_local: + last_png = os.path.join(mapdl.directory, last_png) + else: + mapdl.download(last_png) + + # the file size will be 3kb if the image is empty. + assert os.path.getsize(last_png) // 1024 > 4 # kbs + + # cleaning + os.remove(last_png)