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