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
30
31
32import sys
33import os
34
35from pathlib import Path
36
37import manufacturingtoolkit.CadExMTK as mtk
38
39sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
40
41import mtk_license as license
42
43class ProgressBarObserver(mtk.ProgressStatus_Observer):
44 def __init__(self):
45 super().__init__()
46
47 def ChangedValue(self, theInfo: mtk.ProgressStatus):
48 print(theInfo.Value())
49
50 def Completed(self, theInfo: mtk.ProgressStatus):
51 print(f"{theInfo.Value()}: complete!")
52
53def main(theSource: str):
54 aKey = license.Value()
55
56 if not mtk.LicenseManager.Activate(aKey):
57 print("Failed to activate Manufacturing Toolkit license.")
58 return 1
59
60 aModel = mtk.ModelData_Model()
61
62
63
64 anObserver = ProgressBarObserver()
65
66 with mtk.ProgressStatus() as aStatus:
67
68 aStatus.Register(anObserver)
69
70
71 with mtk.ProgressScope(aStatus) as aTopScope:
72
73 with mtk.ProgressScope(aTopScope, 50) as aReaderScope:
74 aReader = mtk.ModelData_ModelReader()
75
76 aReader.SetProgressStatus(aStatus)
77 aReader.Read(mtk.UTF16String(theSource), aModel)
78
79 if not aModel.IsEmpty() and not aStatus.WasCanceled():
80
81 with mtk.ProgressScope(aTopScope, 50):
82 aMesher = mtk.ModelAlgo_MeshGenerator()
83
84 aMesher.SetProgressStatus(aStatus)
85 aMesher.Generate(aModel)
86
87
88
89 return 0
90
91if __name__ == "__main__":
92 if len(sys.argv) != 2:
93 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
94 print(" <input_file> is a name of the file to be read")
95 sys.exit(1)
96
97 aSource = os.path.abspath(sys.argv[1])
98
99 sys.exit(main(aSource))