Skip to content

Commit

Permalink
Result._plot_point_scalars: Use argument return_cpos in any case and …
Browse files Browse the repository at this point in the history
…fix screenshot function on Windows OS (#73)

* Result._plot_point_scalars: Use argument return_cpos in any case

... before, it was used only, when `if animate`. Now, it used in any case of the call `plotter.show`.

* Result._plot_point_scalars: fix screenshot function on Windows OS

pyvista\plotting\plotting.py:4882: On Windows OS "in the event that the user hits
the exit-button on the GUI then it must be finalized and deleted as accessing it
will kill the kernel... proper screenshots cannot be saved if this happens"
Therefore, when you used ´_plot_point_scalars(..., screenshot=...)´, you got at
ansys\mapdl\reader\rst.py:2830:
´RuntimeError: This plotter is closed and unable to save a screenshot.´

The only solution is, to pass the ´screenshot´ argument to ´plotter.show´
as done in this patch.

* Result._plot_point_scalars: future-safe pyvista version check

... the old version would break with version 1.0.0.
I used the same compare operation as in
<https://github.com/rbarrois/python-semanticversion/blob/master/semantic_version/base.py>
tested manually.
  • Loading branch information
beppo-dd authored Oct 13, 2021
1 parent a5e952b commit 827437a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions ansys/mapdl/reader/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,11 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None,
result_text = self.text_result_table(rnum)
plotter.add_text(result_text, font_size=20, color=text_color)

# camera position added in 0.32.0
show_kwargs = {}
if pv._version.version_info >= (0, 32, 0):
show_kwargs['return_cpos'] = return_cpos

if animate:
if off_screen: # otherwise this never exits
loop = False
Expand All @@ -2761,11 +2766,6 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None,

orig_pts = copied_mesh.points.copy()

# camera position added in 0.32.0
show_kwargs = {}
if pv._version.version_info[1] > 31:
show_kwargs['return_cpos'] = return_cpos

plotter.show(interactive=False, auto_close=False,
window_size=window_size,
full_screen=full_screen,
Expand Down Expand Up @@ -2819,20 +2819,19 @@ def q_callback():
plotter.close()
cpos = plotter.camera_position

elif screenshot:
cpos = plotter.show(auto_close=False, interactive=interactive,
window_size=window_size,
full_screen=full_screen)
if screenshot is True:
img = plotter.screenshot()
else:
plotter.screenshot(screenshot)
plotter.close()
elif screenshot is True:
cpos, img = plotter.show(interactive=interactive,
window_size=window_size,
full_screen=full_screen,
screenshot=screenshot,
**show_kwargs)

else:
cpos = plotter.show(interactive=interactive,
window_size=window_size,
full_screen=full_screen)
full_screen=full_screen,
screenshot=screenshot,
**show_kwargs)

if screenshot is True:
return cpos, img
Expand Down

0 comments on commit 827437a

Please sign in to comment.