def test_stl_exporter_happy_path(box_shape): r"""Happy path""" filename = path_from_file(__file__, "./models_out/box.sTl") exporter = StlExporter(filename) exporter.set_shape(box_shape) exporter.write_file() assert os.path.isfile(filename)
def test_stl_exporter_happy_path_shape_subclass(box_shape): r"""Happy path with a subclass of TopoDS_Shape""" filename = path_from_file(__file__, "./models_out/box.stl") exporter = StlExporter(filename) solid = shape_to_topology(box_shape) assert isinstance(solid, TopoDS_Solid) exporter.set_shape(solid) exporter.write_file() assert os.path.isfile(filename)
def shape_to_stl(shape_, stl_file_, scale, ascii_mode_, factor_, use_min_dim_): r"""Write a single shape to an STL file Parameters ---------- shape_ stl_file_ ascii_mode_ factor_ use_min_dim_ """ exporter = StlExporter(filename=stl_file_, ascii_mode=ascii_mode_) shape_ = scale_uniform(shape_, (0, 0, 0), scale, False) # Must mesh ! Otherwise the exporter does not write anything! mesh(shape_, factor=factor_, use_min_dim=use_min_dim_) exporter.set_shape(shape_) exporter.write_file()
def test_stl_exporter_overwrite(box_shape): r"""Happy path with a subclass of TopoDS_Shape""" filename = path_from_file(__file__, "./models_out/box.stl") exporter = StlExporter(filename) solid = shape_to_topology(box_shape) assert isinstance(solid, TopoDS_Solid) exporter.set_shape(solid) exporter.write_file() assert os.path.isfile(filename) # read the written box.stl importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells == 1 # set a sphere and write again with same exporter sphere = BRepPrimAPI_MakeSphere(10) exporter.set_shape(sphere.Shape()) # this creates a file with a sphere only, this is STL specific exporter.write_file() # check that the file contains the sphere only importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells == 1 # create a new exporter and overwrite with a box only filename = path_from_file(__file__, "./models_out/box.stl") exporter = StlExporter(filename) solid = shape_to_topology(box_shape) exporter.set_shape(solid) exporter.write_file() assert os.path.isfile(filename) # check the file only contains a box importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells == 1
#!/usr/bin/env python # coding: utf-8 r"""Exporting a shape to STL""" from __future__ import print_function import logging from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from aocxchange.stl import StlExporter # from corelib.core.files import path_from_file from corelibpy import path_from_file logging.basicConfig(level=logging.DEBUG, format='%(asctime)s :: %(levelname)6s :: %(module)20s :: ' '%(lineno)3d :: %(message)s') # First create a simple shape to export my_box_shape = BRepPrimAPI_MakeBox(50, 50, 50).Shape() # Export to STL. If ASCIIMode is set to False, then binary format is used. filename = path_from_file(__file__, "./models_out/result_export.stl") my_stl_exporter = StlExporter(filename, ascii_mode=True) my_stl_exporter.set_shape(my_box_shape) my_stl_exporter.write_file()