Skip to content

Commit

Permalink
Plot screenshots using "s" key (#844)
Browse files Browse the repository at this point in the history
* added key shortcut to plot to export screenshot

* Plot Screenshots

* Plot Screenshots

* Plot improvements

* Apply suggestions from code review

* Update pyaedt/generic/plot.py

Co-authored-by: Alberto-DM <84965833+Alberto-DM@users.noreply.github.com>

* Update pyaedt/generic/plot.py

Co-authored-by: Alberto-DM <84965833+Alberto-DM@users.noreply.github.com>

* Plot improvements

* Added Area to Primitives

Co-authored-by: Alberto-DM <84965833+Alberto-DM@users.noreply.github.com>
  • Loading branch information
maxcapodi78 and Alberto-DM authored Feb 9, 2022
1 parent 92aaf30 commit 8f452e1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
27 changes: 23 additions & 4 deletions pyaedt/generic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import os
import time
import warnings
from datetime import datetime

from pyaedt import aedt_exception_handler
from pyaedt.generic.constants import CSS4_COLORS, AEDT_UNITS
from pyaedt.generic.general_methods import is_ironpython, convert_remote_object
import tempfile

if not is_ironpython:
try:
Expand Down Expand Up @@ -964,7 +966,7 @@ def __call__(self, state):

@aedt_exception_handler
def plot(self, export_image_path=None):
"""Plot the current available Data.
"""Plot the current available Data. With `s` key a screenshot is saved in export_image_path or in tempdir.
Parameters
----------
Expand Down Expand Up @@ -1042,12 +1044,29 @@ def plot(self, export_image_path=None):
else:
self.pv.isometric_view()
self.pv.camera.zoom(self.zoom)
if export_image_path:
path_image = os.path.dirname(export_image_path)
root_name, format = os.path.splitext(os.path.basename(export_image_path))
else:
path_image = tempfile.gettempdir() # pragma: no cover
format = ".png" # pragma: no cover
root_name = "Image" # pragma: no cover

def s_callback(): # pragma: no cover
"""save screenshots"""
exp = os.path.join(
path_image, "{}{}{}".format(root_name, datetime.now().strftime("%Y_%M_%d_%H-%M-%S"), format)
)
self.pv.screenshot(exp, return_img=False)

self.pv.add_key_event("s", s_callback)
if export_image_path:
self.pv.show(screenshot=export_image_path, full_screen=True)
elif self.is_notebook:
self.pv.show()
elif self.is_notebook: # pragma: no cover
self.pv.show() # pragma: no cover
else:
self.pv.show(full_screen=True)
self.pv.show(full_screen=True) # pragma: no cover

self.image_file = export_image_path
return True

Expand Down
1 change: 1 addition & 0 deletions pyaedt/modeler/Object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ def material_name(self):
if mat:
self._material_name = mat.strip('"').lower()
return self._material_name
return ""

@material_name.setter
def material_name(self, mat):
Expand Down
7 changes: 3 additions & 4 deletions pyaedt/modules/AdvancedPostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,14 @@ def plot_field_from_fieldplot(
if not file_to_add:
return False
else:
if meshplot:
if self._app._aedt_version >= "2021.2":
models = self.export_model_obj(export_as_single_objects=True, air_objects=False)
if self._app._aedt_version >= "2021.2":
models = self.export_model_obj(export_as_single_objects=True, air_objects=False)

model = ModelPlotter()
model.off_screen = not show

if file_to_add:
model.add_field_from_file(file_to_add, coordinate_units=self.modeler.model_units)
model.add_field_from_file(file_to_add, coordinate_units=self.modeler.model_units, show_edges=meshplot)
if plot_label:
model.fields[0].label = plot_label
if models:
Expand Down

0 comments on commit 8f452e1

Please sign in to comment.