pyvista.read#
- read(
- filename: str | Path | Sequence[str | Path],
- force_ext: str | None = None,
- file_format: str | None = None,
- progress_bar: bool = False,
Read any file type supported by
vtk
ormeshio
.Automatically determines the correct reader to use then wraps the corresponding mesh as a pyvista object. Attempts native
vtk
readers first then tries to usemeshio
.Pickled
meshes ('.pkl'
or'.pickle'
) are also supported.See
pyvista.get_reader()
for list of vtk formats supported.Note
See nschloe/meshio for formats supported by
meshio
. Be sure to installmeshio
withpip install meshio
if you wish to use it.Added in version 0.45: Support reading pickled meshes.
Warning
The pickle module is not secure. Only read pickled mesh files (
'.pkl'
or'.pickle'
) you trust. Seepickle
for details.- Parameters:
- filename
str
,Path
,Sequence
[str
|Path
] The string path to the file to read. If a list of files is given, a
pyvista.MultiBlock
dataset is returned with each file being a separate block in the dataset.- force_ext
str
,optional
If specified, the reader will be chosen by an extension which is different to its actual extension. For example,
'.vts'
,'.vtu'
.- file_format
str
,optional
Format of file to read with meshio.
- progress_barbool, default:
False
Optionally show a progress bar. Ignored when using
meshio
.
- filename
- Returns:
pyvista.DataSet
Wrapped PyVista dataset.
See also
pyvista.DataObject.save
Save a mesh to file.
Examples
Load an example mesh.
>>> import pyvista as pv >>> from pyvista import examples >>> mesh = pv.read(examples.antfile) >>> mesh.plot(cpos='xz')
Load a vtk file.
>>> mesh = pv.read('my_mesh.vtk')
Load a meshio file.
>>> mesh = pv.read('mesh.obj')
Load a pickled mesh file.
>>> mesh = pv.read('mesh.pkl')