|
17 | 17 |
|
18 | 18 | import os
|
19 | 19 | 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 |
21 | 22 |
|
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() |
23 | 31 |
|
24 | 32 | # set the directory where to output the
|
25 | 33 | directory = os.path.split(__name__)[0]
|
26 | 34 | stl_output_dir = os.path.abspath(os.path.join(directory, "models"))
|
27 | 35 |
|
28 | 36 | # make sure the path exists otherwise OCE get confused
|
29 | 37 | 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") |
32 | 39 | stl_exporter = StlAPI_Writer()
|
33 | 40 | 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