Skip to content

Plot screenshots using "s" key #844

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

Merged
merged 9 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 5 additions & 8 deletions _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ class TestClass:
def setup_class(self):
# set a scratch directory and the environment / test data
with Scratch(scratch_path) as self.local_scratch:
try:
example_project = os.path.join(local_path, "example_models", test_project_name + ".aedtz")
self.test_project = self.local_scratch.copyfile(example_project)
example_project2 = os.path.join(local_path, "example_models", test_field_name + ".aedtz")
self.test_project2 = self.local_scratch.copyfile(example_project2)
self.aedtapp = Hfss(self.test_project)
except:
pass
example_project = os.path.join(local_path, "example_models", test_project_name + ".aedtz")
self.test_project = self.local_scratch.copyfile(example_project)
example_project2 = os.path.join(local_path, "example_models", test_field_name + ".aedtz")
self.test_project2 = self.local_scratch.copyfile(example_project2)
self.aedtapp = Hfss(self.test_project)

def teardown_class(self):
self.aedtapp._desktop.ClearMessages("", "", 3)
Expand Down
22 changes: 21 additions & 1 deletion 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,30 @@ 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)
format = export_image_path.split(".")[-1]
root_name = os.path.splitext(os.path.basename(export_image_path))[0]
else:
path_image = tempfile.gettempdir()
format = "png"
root_name = "Image"

def s_callback():
"""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()
else:
self.pv.show(full_screen=True)

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
12 changes: 5 additions & 7 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 Expand Up @@ -402,9 +401,8 @@ def animate_fields_from_aedtplt(
else:
self.ofieldsreporter.UpdateQuantityFieldsPlots(plot_folder)
models_to_add = []
if meshplot:
if self._app._aedt_version >= "2021.2":
models_to_add = self.export_model_obj(export_as_single_objects=True, air_objects=False)
if self._app._aedt_version >= "2021.2":
models_to_add = self.export_model_obj(export_as_single_objects=True, air_objects=False)
fields_to_add = []
if not project_path:
project_path = self._app.working_directory
Expand Down