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

Fix having to plot twice to get a file with size bigger than 3kb #2141

Merged
merged 6 commits into from
Jul 24, 2023
Merged
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
7 changes: 7 additions & 0 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)