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
41
42class DrawingElementVisitor(mtk.Drawing_ElementVoidVisitor):
43 def __init__(self):
44 super().__init__()
45 self.myCurveSetCounter = 0
46
47 def VisitCurveSet(self, theElement: mtk.Drawing_CurveSet):
48 print (f"------- CurveSet <{self.myCurveSetCounter}>")
49 print (f"------- number of curves: {theElement.NumberOfCurves()}")
50 self.myCurveSetCounter += 1
51
52
53def ExploreSheet(theSheet: mtk.Drawing_Sheet):
54 aViewIt = mtk.Drawing_Sheet_ViewIterator(theSheet)
55 aViewCounter = 0
56 while aViewIt.HasNext():
57 aView = aViewIt.Next()
58 print (f"---- View <{aViewCounter}>")
59 aVisitor = DrawingElementVisitor()
60 aView.Accept(aVisitor)
61 aViewCounter += 1
62
63
64def ExploreDrawing(theDrawing: mtk.Drawing_Drawing):
65 aSheetIt = mtk.Drawing_Drawing_SheetIterator(theDrawing)
66 aSheetCounter = 0
67 while (aSheetIt.HasNext()):
68 aSheet = aSheetIt.Next()
69 print (f"-- Sheet <{aSheetCounter}>")
70 ExploreSheet(aSheet)
71 aSheetCounter += 1
72
73def main(theSource: str):
74 aKey = license.Value()
75
76 if not mtk.LicenseManager.Activate(aKey):
77 print("Failed to activate Manufacturing Toolkit license.")
78 return 1
79
80
81 aReaderParameters = mtk.ModelData_ModelReaderParameters()
82 aReaderParameters.SetReadDrawing(True)
83 aReader = mtk.ModelData_ModelReader()
84 aReader.SetParameters(aReaderParameters)
85
86 aModel = mtk.ModelData_Model()
87
88 if not aReader.Read (mtk.UTF16String(theSource), aModel):
89 print(f"Failed to read the file {theSource}")
90 return 1
91
92 aDrawing = aModel.Drawing()
93 if aDrawing.IsNull():
94 print("The model doesn't contain a drawing")
95 return 1
96
97 print(f"Drawing \"{aModel.Name()}\":")
98 ExploreDrawing (aDrawing)
99
100 return 0
101
102if __name__ == "__main__":
103 if len(sys.argv) != 2:
104 print("Usage: <input_file>, where:")
105 print(" <input_file> is a name of the file to be read")
106 sys.exit()
107
108 aSource = os.path.abspath(sys.argv[1])
109
110 sys.exit(main(aSource))