Skip to content

Commit bb13189

Browse files
committed
Fixed and improved the STL exporter example, see issue #296
1 parent a784419 commit bb13189

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

examples/core_export_stl.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,38 @@
1717

1818
import os
1919
from OCC.StlAPI import StlAPI_Writer
20-
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
20+
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
21+
from OCC.BRepMesh import BRepMesh_IncrementalMesh
2122

22-
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
23+
# first, create the shape
24+
my_torus = BRepPrimAPI_MakeTorus(20., 10.).Shape()
25+
# then mesh it. This mesh is used by the STL exporter
26+
# Note : if the mesh is not performed, the STL exporter
27+
# won't do nothing
28+
mesh = BRepMesh_IncrementalMesh(my_torus, 0.9)
29+
mesh.Perform()
30+
assert mesh.IsDone()
2331

2432
# set the directory where to output the
2533
directory = os.path.split(__name__)[0]
2634
stl_output_dir = os.path.abspath(os.path.join(directory, "models"))
2735

2836
# make sure the path exists otherwise OCE get confused
2937
assert os.path.isdir(stl_output_dir)
30-
stl_output_file = os.path.join(stl_output_dir, "box.stl")
31-
38+
stl_low_resolution_file = os.path.join(stl_output_dir, "torus_low_resolution.stl")
3239
stl_exporter = StlAPI_Writer()
3340
stl_exporter.SetASCIIMode(True) # change to False if you need binary export
34-
stl_exporter.Write(my_box, stl_output_file)
41+
stl_exporter.Write(my_torus, stl_low_resolution_file)
42+
# make sure the program was created
43+
assert os.path.isfile(stl_low_resolution_file)
44+
45+
# then we change the mesh resolution
46+
#
47+
mesh.SetDeflection(0.05)
48+
mesh.Perform()
49+
assert mesh.IsDone()
50+
stl_high_resolution_file = os.path.join(stl_output_dir, "torus_high_resolution.stl")
51+
# we set the format to binary
52+
stl_exporter.SetASCIIMode(False)
53+
stl_exporter.Write(my_torus, stl_high_resolution_file)
54+
assert os.path.isfile(stl_high_resolution_file)

0 commit comments

Comments
 (0)