Skip to content

Commit f752c5a

Browse files
authored
Minor revision of the Shaft class (#66)
* Minor revision of the Shaft class * shaft.py: raise Exception on the shaft file format included
1 parent 7c91106 commit f752c5a

File tree

3 files changed

+8195
-8
lines changed

3 files changed

+8195
-8
lines changed

bladex/shaft.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from OCC.Core.IGESControl import IGESControl_Reader
3+
from OCC.Extend.DataExchange import read_stl_file
34
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid, BRepBuilderAPI_Sewing
45
import OCC.Core.TopoDS
56
from 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

Comments
 (0)