save_pickle

Contents

save_pickle#

save_pickle(filename: str | Path, mesh: DataObject) None[source]#

Pickle a mesh and save it to file.

Parameters:
filenamestr

The path of the pickled mesh to save, including the extension '.pkl' or '.pickle'.

meshpyvista.DataObject

Any PyVista mesh.

Examples

Save a pickled mesh and read it.

>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.load_ant()
>>> pv.save_pickle('ant.pkl', mesh)
>>> new_mesh = pv.read_pickle('ant.pkl')
>>> new_mesh
PolyData (...)
  N Cells:    912
  N Points:   486
  N Strips:   0
  X Bounds:   -1.601e+01, 1.601e+01
  Y Bounds:   -9.385e+00, 9.385e+00
  Z Bounds:   -1.678e+01, 1.678e+01
  N Arrays:   0

Unlike other file formats, custom attributes are saved with pickled meshes.

>>> pv.set_new_attribute(mesh, 'custom_attribute', 42)
>>> pv.save_pickle('ant.pkl', mesh)
>>> new_mesh = pv.read_pickle('ant.pkl')
>>> new_mesh.custom_attribute
42