MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / save_mesh

Function save_mesh

python/pymesh/meshio.py:145–187  ·  view source on GitHub ↗

Save mesh to file. Args: filename (:py:class:`str`): Output file. File format is auto detected from extension. mesh (:py:class:`Mesh`): Mesh object. *attributes (:py:class:`list`): (optional) Attribute names to be saved. This field would be ignored if the o

(filename, mesh, *attributes, **setting)

Source from the content-addressed store, hash-verified

143 num_vertex_per_voxel)
144
145def save_mesh(filename, mesh, *attributes, **setting):
146 """ Save mesh to file.
147
148 Args:
149 filename (:py:class:`str`): Output file. File format is auto detected from extension.
150 mesh (:py:class:`Mesh`): Mesh object.
151 *attributes (:py:class:`list`): (optional) Attribute names to be saved.
152 This field would be ignored if the output format does not support
153 attributes (e.g. **.obj** and **.stl** files)
154 **setting (:py:class:`dict`): (optional) The following keys are recognized.
155
156 * ascii: whether to use ascii encoding, default is false.
157 * use_float: store scalars as float instead of double, default is
158 false.
159 * anonymous: whether to indicate the file is generated by PyMesh.
160
161 Raises:
162 KeyError: Attributes cannot be found in mesh.
163
164 Example:
165
166 >>> box = pymesh.generate_box_mesh()
167 >>> pymesh.save_mesh("tmp.stl", box, ascii=True)
168 """
169 ext = os.path.splitext(filename)[1]
170 if ext == ".geogram":
171 PyMesh.save_geogram_mesh(filename, mesh.raw_mesh)
172 return
173 elif ext == ".svg":
174 save_svg(filename, mesh)
175 return
176 writer = PyMesh.MeshWriter.create(filename)
177 for attr in attributes:
178 if not mesh.has_attribute(attr):
179 raise KeyError("Attribute {} is not found in mesh".format(attr))
180 writer.with_attribute(attr)
181 if setting.get("ascii", False):
182 writer.in_ascii()
183 if setting.get("use_float", False):
184 writer.use_float()
185 if setting.get("anonymous", False):
186 writer.set_anonymous()
187 writer.write_mesh(mesh.raw_mesh)

Callers 10

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
quick_csgFunction · 0.70
save_meshMethod · 0.70
tetrahedralizeFunction · 0.70
init_GeogramFunction · 0.50

Calls 9

save_svgFunction · 0.90
set_anonymousMethod · 0.80
createMethod · 0.45
has_attributeMethod · 0.45
with_attributeMethod · 0.45
getMethod · 0.45
in_asciiMethod · 0.45
use_floatMethod · 0.45
write_meshMethod · 0.45

Tested by 1

save_meshMethod · 0.56