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 mtk.MTKCore 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 LicenseHelper
43import shape_processor
44
45class PartProcessor(shape_processor.SolidProcessor):
46 def __init__(self, theResolution):
47 super().__init__()
48 aVoxelizationParameters = mtk.WallThickness_VoxelizationParameters()
49 aVoxelizationParameters.SetResolution(theResolution)
50 aParameters = mtk.WallThickness_AnalyzerParameters()
51 aParameters.SetVoxelizationParameters(aVoxelizationParameters)
52 aParameters.SetMethod(mtk.WallThickness_Method_Voxelization)
53 self.myAnalyzer = mtk.WallThickness_Analyzer(aParameters)
54
55 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
56 aWTData = self.myAnalyzer.Perform(theSolid)
57 self.PrintWTData(aWTData)
58
59 def PrintWTData(self, theData: mtk.WallThickness_Data):
60 if theData.IsEmpty() != True:
61 print(" Min thickness = ", theData.MinThickness(), " mm", sep="")
62 print(" Max thickness = ", theData.MaxThickness(), " mm\n", sep="")
63 else:
64 print(" Failed to analyze the wall thickness of this entity.\n")
65
66def main(theSource: str, theRes: int):
67 aKey = license.Value()
68
69 if not LicenseHelper.SetupRuntimeKey() :
70 return 1
71
72 try:
73 mtk.LicenseManager.Activate(aKey)
74 except mtk.LicenseError as anException:
75 mtk.LicenseManager.Deactivate()
76 print("Failed to activate Manufacturing Toolkit license: " + anException.what())
77 return 1
78
79 if theRes < 100:
80 print("WARNING: Input resolution \"" + theRes + "\" < 100. Will be used default resolution.\n")
81 theRes = 1000
82
83 aModel = mtk.ModelData_Model()
84 aReader = mtk.ModelData_ModelReader()
85
86
87 if not aReader.Read(mtk.UTF16String(theSource), aModel):
88 mtk.LicenseManager.Deactivate()
89 print("Failed to open and convert the file " + theSource)
90 return 1
91
92 print("Model: ", aModel.Name(), "\n", sep="")
93
94
95 aPartProcessor = PartProcessor(theRes)
96 aVisitor = mtk.ModelData_ModelElementUniqueVisitor(aPartProcessor)
97 aModel.Accept(aVisitor)
98
99 mtk.LicenseManager.Deactivate()
100
101 return 0
102
103if __name__ == "__main__":
104 if len(sys.argv) < 2 or len(sys.argv) > 3:
105 print("Usage: <input_file> <input_resolution>, where:")
106 print(" <input_file> is a name of the file to be read")
107 print(" <input_resolution> is an optional argument that determine accuracy")
108 print(" of wall thickness calculation.")
109 print(" The larger the value, the higher the accuracy of the calculations,")
110 print(" but greatly increase computation time and memory usage.")
111 print(" Should be at least 100.")
112 sys.exit()
113
114 aSource = os.path.abspath(sys.argv[1])
115 if len(sys.argv) == 3:
116 aRes = sys.argv[2]
117 else:
118 aRes = 1000
119
120 sys.exit(main(aSource, aRes))