Note
Go to the end to download the full example code.
Name filtering in the Plotly backend#
The name_filter parameter accepts a regular-expression string and is
available on Plotter.plot(), Plotter.plot_iter(), and
Plotter.show(). Only MeshObjectPlot objects whose name
matches the pattern are added to the figure; everything else is silently
skipped.
import pyvista as pv
from ansys.tools.visualization_interface import Plotter
from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend
from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot
class Part:
"""Minimal domain object with a name."""
def __init__(self, name: str):
self.name = name
Build a set of named parts#
parts = [
MeshObjectPlot(Part("Wheel_FL"), pv.Sphere(center=(-1, 1, 0), radius=0.3)),
MeshObjectPlot(Part("Wheel_FR"), pv.Sphere(center=( 1, 1, 0), radius=0.3)),
MeshObjectPlot(Part("Wheel_RL"), pv.Sphere(center=(-1, -1, 0), radius=0.3)),
MeshObjectPlot(Part("Wheel_RR"), pv.Sphere(center=( 1, -1, 0), radius=0.3)),
MeshObjectPlot(Part("Chassis"), pv.Box(bounds=(-0.8, 0.8, -1.2, 1.2, 0, 0.4))),
]
Show with name_filter via show()#
Pass name_filter directly to Plotter.show() together with the
list of objects. The filter is applied while plotting, so only matching
parts are added to the figure.
pl = Plotter(backend=PlotlyBackend())
pl.show(plottable_object=parts)
pl = Plotter(backend=PlotlyBackend())
pl.show(plottable_object=parts, name_filter="Wheel")
Total running time of the script: (0 minutes 0.036 seconds)