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.CadExMTK as mtk
36
37sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../"))
38
39import mtk_license as license
40
41class SceneGraphPolyProjector(mtk.ModelData_ModelElementVoidVisitor):
42 def __init__(self, theDirection: mtk.Geom_Direction):
43 super().__init__()
44 self.myDirection = theDirection
45 self.myProjector = mtk.Projector_PolyProjector()
46
47 def VisitPart(self, thePart: mtk.ModelData_Part):
48 aData = self.myProjector.Perform(thePart, self.myDirection)
49 print(f"Part projection [{thePart.Name()}] has:")
50 print(f" area = {aData.ProjectionArea()} mm\n")
51
52def main(theSource: str):
53 aKey = license.Value()
54
55 if not mtk.LicenseManager.Activate(aKey):
56 print("Failed to activate Manufacturing Toolkit license.")
57 return 1
58
59 aModel = mtk.ModelData_Model()
60 aReader = mtk.ModelData_ModelReader()
61
62
63 if not aReader.Read(mtk.UTF16String(theSource), aModel):
64 print("Failed to open and convert the file " + theSource)
65 return 1
66
67 print("Model: ", aModel.Name(), "\n", sep="")
68
69
70 aProjector = SceneGraphPolyProjector(mtk.Geom_Direction.YDir())
71 aModel.Accept(aProjector)
72
73 return 0
74
75if __name__ == "__main__":
76 if len(sys.argv) != 2:
77 print("Usage: <input_file>, where:")
78 print(" <input_file> is a name of the file to be read")
79 sys.exit()
80
81 aSource = os.path.abspath(sys.argv[1])
82
83 sys.exit(main(aSource))