11import os
22from OCC .Core .IGESControl import IGESControl_Reader
3+ from OCC .Extend .DataExchange import read_stl_file
34from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_MakeSolid , BRepBuilderAPI_Sewing
45import OCC .Core .TopoDS
56from OCC .Display .SimpleGui import init_display
@@ -8,9 +9,9 @@ class Shaft(object):
89 """
910 Bottom-up parametrized shaft construction.
1011
11- :param string filename: path (with the file extension) of a .iges file with
12+ :param string filename: path (with the file extension) of a .stl or . iges file with
1213 stored shaft information.
13- :cvar string filename: path (with the file extension) of a .iges file with
14+ :cvar string filename: path (with the file extension) of a .stl or . iges file with
1415 stored shaft information.
1516 """
1617
@@ -27,10 +28,16 @@ def generate_solid(self):
2728 :return: solid shaft
2829 :rtype: OCC.Core.TopoDS.TopoDS_Solid
2930 """
30- iges_reader = IGESControl_Reader ()
31- iges_reader .ReadFile (self .filename )
32- iges_reader .TransferRoots ()
33- shaft_compound = iges_reader .Shape ()
31+ ext = os .path .splitext (self .filename )[1 ][1 :]
32+ if ext == 'stl' :
33+ shaft_compound = read_stl_file (self .filename )
34+ elif ext == 'iges' :
35+ iges_reader = IGESControl_Reader ()
36+ iges_reader .ReadFile (self .filename )
37+ iges_reader .TransferRoots ()
38+ shaft_compound = iges_reader .Shape ()
39+ else :
40+ raise Exception ('The shaft file is not in iges/stl formats' )
3441 sewer = BRepBuilderAPI_Sewing (1e-2 )
3542 sewer .Add (shaft_compound )
3643 sewer .Perform ()
0 commit comments