Skip to content

Commit 21ecd6a

Browse files
committed
add ansys visualization interface plotter
1 parent 171ca17 commit 21ecd6a

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
77
name = "ansys-mechanical-core"
8-
version = "0.11.dev0"
8+
version = "0.12.dev0"
99
description = "A python wrapper for Ansys Mechanical"
1010
readme = "README.rst"
1111
requires-python = ">=3.9,<4.0"
@@ -80,7 +80,7 @@ doc = [
8080
"sphinxemoji==0.3.1",
8181
]
8282
viz = [
83-
"pyvista>=0.39.1",
83+
"ansys-tools-visualization-interface==0.2.6",
8484
"usd-core==24.3",
8585
]
8686

src/ansys/mechanical/core/embedding/app.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
from ansys.mechanical.core.embedding.warnings import connect_warnings, disconnect_warnings
3535

3636
try:
37-
import pyvista # noqa: F401
37+
import ansys.tools.visualization_interface # noqa: F401
3838

39-
HAS_PYVISTA = True
39+
HAS_ANSYS_VIZ = True
4040
"""Whether or not PyVista exists."""
4141
except:
4242

43-
HAS_PYVISTA = False
43+
HAS_ANSYS_VIZ = False
4444

4545

4646
def _get_default_addin_configuration() -> AddinConfiguration:
@@ -229,13 +229,9 @@ def execute_script(self, script: str) -> typing.Any:
229229
rets = None
230230
return self.script_engine.ExecuteCode(script, SCRIPT_SCOPE, light_mode, args, rets)
231231

232-
def plot(self) -> None:
233-
"""Visualize the model in 3d.
234-
235-
Requires installation using the viz option. E.g.
236-
pip install ansys-mechanical-core[viz]
237-
"""
238-
if not HAS_PYVISTA:
232+
def plotter(self):
233+
"""Return ansys.tools.visualization_interface Plotter object."""
234+
if not HAS_ANSYS_VIZ:
239235
warnings.warn(
240236
"Installation of viz option required! Use pip install ansys-mechanical-core[viz]"
241237
)
@@ -245,9 +241,21 @@ def plot(self) -> None:
245241
warnings.warn("Plotting is only supported with version 2024R2 and later!")
246242
return
247243

248-
from ansys.mechanical.core.embedding.viz.pyvista_plotter import plot_model
244+
# TODO Check if anything loaded inside app or else show warning and return
245+
246+
from ansys.mechanical.core.embedding.viz.pyvista_plotter import to_pyvista_plotter
247+
248+
return to_pyvista_plotter(self)
249+
250+
def plot(self) -> None: # TODO : add clipping plane
251+
"""Visualize the model in 3d.
252+
253+
Requires installation using the viz option. E.g.
254+
pip install ansys-mechanical-core[viz]
255+
"""
256+
_plotter = self.plotter()
249257

250-
plot_model(self)
258+
return _plotter.show()
251259

252260
@property
253261
def poster(self) -> Poster:

src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import Ansys # isort: skip
3131

32+
from ansys.tools.visualization_interface import Plotter
3233
import numpy as np
3334
import pyvista as pv
3435

@@ -57,7 +58,7 @@ def _get_nodes_and_coords(tri_tessellation: "Ansys.Mechanical.Scenegraph.TriTess
5758

5859
def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"):
5960
"""Convert the app's geometry to a pyvista plotter instance."""
60-
plotter = pv.Plotter()
61+
plotter = Plotter()
6162
for body in app.DataModel.GetObjectsByType(
6263
Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body
6364
):
@@ -68,9 +69,3 @@ def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"):
6869
color = pv.Color(bgr_to_rgb_tuple(body.Color))
6970
plotter.add_mesh(polydata, color=color, smooth_shading=True)
7071
return plotter
71-
72-
73-
def plot_model(app: "ansys.mechanical.core.embedding.App"):
74-
"""Plot the model."""
75-
plotter = to_pyvista_plotter(app)
76-
plotter.show()

0 commit comments

Comments
 (0)