navis.write_mesh¶
- navis.write_mesh(x, filepath=None, filetype=None)[source]¶
Export meshes (MeshNeurons, Volumes, Trimeshes) to disk.
Under the hood this is using trimesh to export meshes.
- Parameters:
x (MeshNeuron | Volume | Trimesh | NeuronList) – If multiple objects, will generate a file for each neuron (see also
filepath
).filepath (None | str | list, optional) – If
None
, will return byte string or list of thereof. If filepath will save to this file. If path will save neuron(s) in that path using{x.id}
as filename(s). If list, input must be NeuronList and a filepath must be provided for each neuron.filetype (stl | ply | obj, optional) – If
filepath
does not include the file extension, you need to provide it asfiletype
.
- Returns:
None – If filepath is not
None
.bytes – If filepath is
None
.
See also
navis.read_mesh()
Import neurons.
navis.write_precomputed()
Write meshes to Neuroglancer’s precomputed format.
Examples
Write
MeshNeurons
to folder:>>> import navis >>> nl = navis.example_neurons(3, kind='mesh') >>> navis.write_mesh(nl, tmp_dir, filetype='obj')
Specify the filenames:
>>> import navis >>> nl = navis.example_neurons(3, kind='mesh') >>> navis.write_mesh(nl, tmp_dir / '{neuron.name}.obj')
Write directly to zip archive:
>>> import navis >>> nl = navis.example_neurons(3, kind='mesh') >>> navis.write_mesh(nl, tmp_dir / 'meshes.zip', filetype='obj')