Box Widget

The box widget can be enabled and disabled by the pyvista.WidgetHelper.add_box_widget() and 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 pyvista.WidgetHelper.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')[-1, -1, 0.2])
box widget


[(-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 (0x7f623a669c90)
  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 11.976 seconds)

Gallery generated by Sphinx-Gallery