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