forked from whjdark/AAGNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep2stl.py
42 lines (29 loc) · 1.16 KB
/
step2stl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
import argparse
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.StlAPI import StlAPI_Writer
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--step_path", type=str, required=True, help="Path to load the step files from")
parser.add_argument("--output", type=str, required=True, help="Path to the save intermediate brep data")
args = parser.parse_args()
# Create a reader object
reader = STEPControl_Reader()
# Read the STEP file
status = reader.ReadFile(args.step_path)
# Check if the file was read successfully
if status == 1:
# Transfer the shape object
reader.TransferRoot()
shape = reader.Shape()
mesh = BRepMesh_IncrementalMesh(shape, 0.1)
# Create a writer object
writer = StlAPI_Writer()
# Write the shape object to an STL file
err = writer.Write(mesh.Shape(), args.output)
# Print a success message
print(err)
else:
# Print an error message
print('Could not read the STEP file.')