Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Box Widget#
The box widget can be enabled and disabled by the
pyvista.Plotter.add_box_widget()
and
pyvista.Plotter.clear_box_widgets()
methods respectively.
When enabling the box widget, you must provide a custom callback function
otherwise the box would appear and do nothing - the callback functions are
what allow us to leverage the widget to perform a task like clipping/cropping.
Considering that using a box to clip/crop a mesh is one of the most common use
cases, we have included a helper method that will allow you to add a mesh to a
scene with a box widget that controls its extent, the
pyvista.Plotter.add_mesh_clip_box()
method.
import pyvista as pv
from pyvista import examples
mesh = examples.download_nefertiti()
p = pv.Plotter()
p.add_mesh_clip_box(mesh, color="white")
p.show(cpos=[-1, -1, 0.2])
After interacting with the scene, the clipped mesh is available as:
[UnstructuredGrid (0x7f1aa0ffa2c0)
N Cells: 2018232
N Points: 1009118
X Bounds: -1.194e+02, 1.194e+02
Y Bounds: -1.813e+02, 1.813e+02
Z Bounds: -2.473e+02, 2.473e+02
N Arrays: 1]
Total running time of the script: (0 minutes 14.080 seconds)