pyvista.MultiBlock#

class MultiBlock(*args, **kwargs)[source]#

A composite class to hold many data sets which can be iterated over.

This wraps/extends the vtkMultiBlockDataSet class so that we can easily plot these data sets and use the composite in a Pythonic manner.

You can think of MultiBlock like a list as we can iterate over this data structure by index. It has some dictionary features as we can also access blocks by their string name.

Changed in version 0.36.0: MultiBlock adheres more closely to being list like, and inherits from collections.abc.MutableSequence. Multiple nonconforming behaviors were removed or modified.

Parameters:
*argsdict, optional

Data object dictionary.

**kwargsdict, optional

See pyvista.read() for additional options.

Examples

>>> import pyvista as pv

Create an empty composite dataset.

>>> blocks = pv.MultiBlock()

Add a dataset to the collection.

>>> sphere = pv.Sphere()
>>> blocks.append(sphere)

Add a named block.

>>> blocks["cube"] = pv.Cube()

Instantiate from a list of objects.

>>> data = [
...     pv.Sphere(center=(2, 0, 0)),
...     pv.Cube(center=(0, 2, 0)),
...     pv.Cone(),
... ]
>>> blocks = pv.MultiBlock(data)
>>> blocks.plot()
../../../_images/pyvista-MultiBlock-1_00_00.png

Instantiate from a dictionary.

>>> data = {
...     "cube": pv.Cube(),
...     "sphere": pv.Sphere(center=(2, 2, 0)),
... }
>>> blocks = pv.MultiBlock(data)
>>> blocks.plot()
../../../_images/pyvista-MultiBlock-1_01_00.png

Iterate over the collection.

>>> for name in blocks.keys():
...     block = blocks[name]
...
>>> for block in blocks:
...     # Do something with each dataset
...     surf = block.extract_surface()
...

Methods

MultiBlock.append(dataset[, name])

Add a data set to the next block index.

MultiBlock.as_polydata_blocks([copy])

Convert all the datasets within this MultiBlock to pyvista.PolyData.

MultiBlock.clean([empty])

Remove any null blocks in place.

MultiBlock.copy([deep])

Return a copy of the multiblock.

MultiBlock.copy_meta_from(ido, deep)

Copy pyvista meta data onto this object from another object.

MultiBlock.extend(datasets)

Extend MultiBlock with an Iterable.

MultiBlock.get(index[, default])

Get a block by its name.

MultiBlock.get_block_name(index)

Return the string name of the block at the given index.

MultiBlock.get_data_range(name[, allow_missing])

Get the min/max of an array given its name across all blocks.

MultiBlock.get_index_by_name(name)

Find the index number by block name.

MultiBlock.insert(index, dataset[, name])

Insert data before index.

MultiBlock.keys()

Get all the block names in the dataset.

MultiBlock.plot([off_screen, full_screen, ...])

Plot a PyVista, numpy, or vtk object.

MultiBlock.pop([index])

Pop off a block at the specified index.

MultiBlock.replace(index, dataset)

Replace dataset at index while preserving key name.

MultiBlock.reverse()

Reverse MultiBlock in-place.

MultiBlock.set_active_scalars(name[, ...])

Find the scalars by name and appropriately set it as active.

MultiBlock.set_block_name(index, name)

Set a block's string name at the specified index.

MultiBlock.shallow_copy(to_copy)

Shallow copy the given multiblock to this multiblock.

MultiBlock.wrap_nested()

Ensure that all nested data structures are wrapped as PyVista datasets.

Attributes

MultiBlock.bounds

Find min/max for bounds across blocks.

MultiBlock.center

Return the center of the bounding box.

MultiBlock.is_all_polydata

Return True when all the blocks are pyvista.PolyData.

MultiBlock.length

Return the length of the diagonal of the bounding box.

MultiBlock.n_blocks

Return the total number of blocks set.

MultiBlock.volume

Return the total volume of all meshes in this dataset.