The box widget can be enabled and disabled by the
pyvista.WidgetHelper.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
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])
[(-1167.493770554712, -1167.493770554712, 233.4987541109424), (0.0, 0.0, 0.0), (0.0, 0.0, 1.0)]
After interacting with the scene, the clipped mesh is available as:
[UnstructuredGrid (0x7fc9001865e0) 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: 0 ]
Total running time of the script: ( 0 minutes 9.249 seconds)