PickingComponent.enable_block_picking#
- PickingComponent.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.MultiBlockand pass it to a callback.- Parameters:
- callback
callable(),optional When input, this picker calls this callable after a selection is made. The composite index is passed to
callbackas the first argument and the dataset as the second argument.- side
str, default: “left” The mouse button to track (either
'left'or'right'). Also accepts'r'or'l'.
- callback
Notes#
The picked block index can be accessed from picked_block_index attribute.
Examples#
Download Python source code | Download Jupyter notebook
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()