# Examples from pyvista.MultiBlock.replace
# ========================================

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()
np.allclose(blocks[1].center, [10.0, 10.0, 10.0])

# 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

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code

