pyvista.Plotter.enable_block_picking

pyvista.Plotter.enable_block_picking#

Plotter.enable_block_picking(callback=None, side='left')[source]#

Enable composite block picking.

Use this picker to return the index of a DataSet when using composite dataset like pyvista.MultiBlock and pass it to a callback.

Parameters:
callbackcallable(), optional

When input, this picker calls this callable after a selection is made. The composite index is passed to callback as the first argument and the dataset as the second argument.

sidestr, default: “left”

The mouse button to track (either 'left' or 'right'). Also accepts 'r' or 'l'.

Notes

The picked block index can be accessed from picked_block_index attribute.

Examples

Enable block picking with a multiblock dataset. Left clicking will turn blocks blue while right picking will turn the block back to the default color.

>>> import pyvista as pv
>>> multiblock = pv.MultiBlock(
...     [pv.Cube(), pv.Sphere(center=(0, 0, 1))]
... )
>>> pl = pv.Plotter()
>>> actor, mapper = pl.add_composite(multiblock)
>>> def turn_blue(index, dataset):
...     mapper.block_attr[index].color = 'blue'
...
>>> pl.enable_block_picking(callback=turn_blue, side='left')
>>> def clear_color(index, dataset):
...     mapper.block_attr[index].color = None
...
>>> pl.enable_block_picking(callback=clear_color, side='right')
>>> pl.show()
../../../_images/pyvista-Plotter-enable_block_picking-1_00_00.png