CompositeAttributes.get_block#
- CompositeAttributes.get_block(index)[source]#
Return a block by its flat index.
- Parameters:
- index
int Flat index of the block to retrieve.
- index
- Returns:
pyvista.DataObjectPyVista data object.
Notes#
This method employs VTK’s flat indexing and allows for accessing both
the blocks of a composite dataset as well as the entire composite
dataset. If there is only one composite dataset, A, which contains
datasets [b, c], the indexing would be [A, b, c].
If there are two composite datasets [B, C] in one composite
dataset, A, each of which containing three additional datasets
[d, e, f], and [g, h, i], respectively, then the head node,
A, would be the zero index, followed by the first child, B,
followed by all the children of B, [d, e, f]. In data
structures, this flat indexing would be known as “Depth-first search”
and the entire indexing would be:
[A, B, d, e, f, C, g, h, i]
Note how the composite datasets themselves are capitalized and are accessible in the flat indexing, and not just the datasets.
Examples#
Download Python source code | Download Jupyter notebook
Add a composite dataset to a plotter and access its block attributes.
Note how the zero index is the entire multiblock and you can use 1
and 2 to access the individual sub-blocks.
>>> import pyvista as pv
>>> dataset = pv.MultiBlock([pv.Cube(), pv.Sphere(center=(0, 0, 1))])
>>> pl = pv.Plotter()
>>> actor, mapper = pl.add_composite(dataset)
>>> mapper.block_attr.get_block(0)
MultiBlock (...)
N Blocks: 2
X Bounds: -5.000e-01, 5.000e-01
Y Bounds: -5.000e-01, 5.000e-01
Z Bounds: -5.000e-01, 1.500e+00
Note this is the same as using __getitem__
>>> mapper.block_attr[0]
Composite Block Addr=... Attributes
Visible: None
Opacity: None
Color: None
Pickable None