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 sys
31import os
32from pathlib import Path
33
34import mtk.MTKCore as mtk
35import mtk.MTKView as view
36
37sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
38sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../helpers/"))
39
40import LicenseHelper
41
42import mtk_license as license
43
44def main(theSource: str, theDest: str):
45 aKey = license.Value()
46
47 if not LicenseHelper.SetupRuntimeKey() :
48 return 1
49
50 try:
51 mtk.LicenseManager.Activate(aKey)
52 except mtk.LicenseError as anException:
53 mtk.LicenseManager.Deactivate()
54 print("Failed to activate Manufacturing Toolkit license: " + anException.what())
55 return 1
56
57 aModel = mtk.ModelData_Model()
58
59
60 if not mtk.ModelData_ModelReader().Read(mtk.UTF16String(theSource), aModel):
61 mtk.LicenseManager.Deactivate()
62 print("Failed to read the file " + theSource)
63 return 1
64
65 aWriter = view.View_ImageWriter()
66 aWriterParameters = view.View_ImageWriterParameters()
67
68
69 aWriterParameters.SetImageWidth(750)
70 aWriterParameters.SetImageHeight(500)
71 aWriterParameters.SetViewIsFitAll(True)
72 aBackgroundColor = view.View_ColorBackgroundStyle(mtk.Materials_Color(255, 255, 255))
73 aWriterParameters.SetViewBackground(aBackgroundColor)
74
75 aWriter.SetParameters(aWriterParameters)
76
77
78 if not aWriter.WriteFile(aModel, mtk.UTF16String(theDest)):
79 mtk.LicenseManager.Deactivate()
80 print("Failed to write the image file " + theDest)
81 return 1
82
83 print("Thumbnail successfully generated: " + theDest)
84
85 mtk.LicenseManager.Deactivate()
86
87 return 0
88
89if __name__ == "__main__":
90 if len(sys.argv) != 3:
91 print(" <input_file> is a name of the model file to be read")
92 print(" <output_file> is a name of the image file to save the model")
93 sys.exit(1)
94
95 aSource = os.path.abspath(sys.argv[1])
96 aDest = os.path.abspath(sys.argv[2])
97
98 sys.exit(main(aSource, aDest))
99