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
30import os
31import sys
32
33from pathlib import Path
34
35import manufacturingtoolkit.CadExMTK as mtk
36
37sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../"))
38sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../helpers/"))
39
40import mtk_license as license
41
42import shape_processor
43
44class PartProcessor(shape_processor.SolidProcessor):
45 def __init__(self):
46 super().__init__()
47 self.myAnalyzer = mtk.WallThickness_Analyzer()
48 self.myResolution = 1000
49
50 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
51 aWTData = self.myAnalyzer.Perform(theSolid, self.myResolution)
52 self.PrintWTData(aWTData)
53
54 def PrintWTData(self, theData: mtk.WallThickness_Data):
55 if theData.IsEmpty() != True:
56 print(" Min thickness = ", theData.MinThickness(), " mm", sep="")
57 print(" Max thickness = ", theData.MaxThickness(), " mm\n", sep="")
58 else:
59 print(" Failed to analyze the wall thickness of this entity.\n")
60
61def main(theSource: str, theRes: int):
62 aKey = license.Value()
63
64 if not mtk.LicenseManager.Activate(aKey):
65 print("Failed to activate Manufacturing Toolkit license.")
66 return 1
67
68 if theRes < 100:
69 print("WARNING: Input resolution \"" + theRes + "\" < 100. Will be used default resolution.\n")
70 theRes = 1000
71
72 aModel = mtk.ModelData_Model()
73 aReader = mtk.ModelData_ModelReader()
74
75
76 if not aReader.Read(mtk.UTF16String(theSource), aModel):
77 print("Failed to open and convert the file " + theSource)
78 return 1
79
80 print("Model: ", aModel.Name(), "\n", sep="")
81
82
83 aPartProcessor = PartProcessor()
84 aPartProcessor.myResolution = theRes
85 aVisitor = mtk.ModelData_ModelElementUniqueVisitor(aPartProcessor)
86 aModel.Accept(aVisitor)
87
88 return 0
89
90if __name__ == "__main__":
91 if len(sys.argv) < 2 or len(sys.argv) > 3:
92 print("Usage: <input_file> <input_resolution>, where:")
93 print(" <input_file> is a name of the file to be read")
94 print(" <input_resolution> is an optional argument that determine accuracy")
95 print(" of wall thickness calculation.")
96 print(" The larger the value, the higher the accuracy of the calculations,")
97 print(" but greatly increase computation time and memory usage.")
98 print(" Should be at least 100.")
99 sys.exit()
100
101 aSource = os.path.abspath(sys.argv[1])
102 if len(sys.argv) == 3:
103 aRes = sys.argv[2]
104 else:
105 aRes = 1000
106
107 sys.exit(main(aSource, aRes))