MultiBlock.replace#
- MultiBlock.replace( ) None[source]#
Replace dataset at index while preserving key name.
- Parameters:
- index
int|Sequence[int] |str Index or name of the block to replace. Specify a sequence of indices to replace a nested block.
Added in version 0.45: Allow indexing nested blocks.
- dataset
pyvista.DataSetorpyvista.MultiBlock Dataset for replacing the one at index.
- index
Examples#
Download Python source code | Download Jupyter notebook
>>> import pyvista as pv
>>> from pyvista import examples
>>> import numpy as np
>>> data = {
... 'cube': pv.Cube(),
... 'sphere': pv.Sphere(center=(2, 2, 0)),
... }
>>> blocks = pv.MultiBlock(data)
>>> blocks.replace(1, pv.Sphere(center=(10, 10, 10)))
>>> blocks.keys()
['cube', 'sphere']
>>> np.allclose(blocks[1].center, [10.0, 10.0, 10.0])
True
Load a dataset with nested blocks.
>>> multi = examples.download_cgns_multi()
Get one of the blocks and extract its surface.
>>> block = multi[0][3]
>>> surface = block.extract_surface(algorithm=None)
Replace the block.
>>> multi.replace((0, 3), surface)
This is similar to replacing the block directly with indexing but the block name is also preserved.
>>> multi[0][3] = surface