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