Picking Meshes#

This example demonstrates how to pick meshes using enable_mesh_picking().

import pyvista as pv

Pick either a cube or a sphere using “p”#

sphere = pv.Sphere(center=(1, 0, 0))
cube = pv.Cube()

pl = pv.Plotter()
pl.add_mesh(sphere, color='r')
pl.add_mesh(cube, color='b')
pl.enable_mesh_picking()
pl.show()
mesh picking

Pick using the left-mouse button#

Pick using the left mouse button and trigger a callback that “shrinks” the mesh each time it’s selected.

def callback(mesh):
    """Shrink the mesh each time it's clicked."""
    shrunk = mesh.shrink(0.9)
    mesh.overwrite(shrunk)  # must operate "in-place" by overwrite


pl = pv.Plotter()
pl.add_mesh(sphere, color='r')
pl.add_mesh(cube, color='b')
pl.enable_mesh_picking(callback=callback, left_clicking=True, show=False)
pl.show()
mesh picking

Total running time of the script: ( 0 minutes 0.529 seconds)

Gallery generated by Sphinx-Gallery