diff --git a/examples/core_export_stl.py b/examples/core_export_stl.py index b090145c3..d13154bda 100644 --- a/examples/core_export_stl.py +++ b/examples/core_export_stl.py @@ -17,9 +17,17 @@ import os from OCC.StlAPI import StlAPI_Writer -from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox +from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus +from OCC.BRepMesh import BRepMesh_IncrementalMesh -my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() +# first, create the shape +my_torus = BRepPrimAPI_MakeTorus(20., 10.).Shape() +# then mesh it. This mesh is used by the STL exporter +# Note : if the mesh is not performed, the STL exporter +# won't do nothing +mesh = BRepMesh_IncrementalMesh(my_torus, 0.9) +mesh.Perform() +assert mesh.IsDone() # set the directory where to output the directory = os.path.split(__name__)[0] @@ -27,8 +35,20 @@ # make sure the path exists otherwise OCE get confused assert os.path.isdir(stl_output_dir) -stl_output_file = os.path.join(stl_output_dir, "box.stl") - +stl_low_resolution_file = os.path.join(stl_output_dir, "torus_low_resolution.stl") stl_exporter = StlAPI_Writer() stl_exporter.SetASCIIMode(True) # change to False if you need binary export -stl_exporter.Write(my_box, stl_output_file) +stl_exporter.Write(my_torus, stl_low_resolution_file) +# make sure the program was created +assert os.path.isfile(stl_low_resolution_file) + +# then we change the mesh resolution +# +mesh.SetDeflection(0.05) +mesh.Perform() +assert mesh.IsDone() +stl_high_resolution_file = os.path.join(stl_output_dir, "torus_high_resolution.stl") +# we set the format to binary +stl_exporter.SetASCIIMode(False) +stl_exporter.Write(my_torus, stl_high_resolution_file) +assert os.path.isfile(stl_high_resolution_file)