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
32
33import sys
34from pathlib import Path
35import os
36
37import cadexchanger.CadExCore as cadex
38
39sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
40import cadex_license as license
41
42class PropertiesVisitor(cadex.ModelData_Model_CombinedElementVisitor):
43 def VisitPart(self, thePart: cadex.ModelData_Part):
44 aPT = thePart.Properties()
45 self.ExplorePropertyTable(aPT)
46
47 aBRep = thePart.BRepRepresentation()
48 if aBRep:
49 aVisitor = SubShapePropertiesVisitor(aBRep)
50 aBRep.Accept(aVisitor)
51
52
53 aPTList = aVisitor.PropertyTables()
54 for i in aPTList:
55 self.ExplorePropertyTable(i)
56
57
58 def VisitEnterSGE(self, theElement: cadex.ModelData_SceneGraphElement) -> bool:
59 aPT = theElement.Properties()
60 self.ExplorePropertyTable(aPT)
61
62 return True
63
64 def ExtractPropertyTables(self, theBRep: cadex.ModelData_BRepRepresentation) -> list:
65 aPTList = []
66 aBodyGen = theBRep.Get()
67 for aBody in aBodyGen:
68 aPTList.append(theBRep.PropertyTable(aBody))
69 return aPTList
70
71 def ExplorePropertyTable(self, thePT: cadex.ModelData_PropertyTable):
72 if thePT and not thePT.IsEmpty():
73 aPropVisitor = PropertyVisitor()
74 thePT.Accept(aPropVisitor)
75 else:
76 print("\nProperty Table is empty")
77
78class PropertyVisitor(cadex.ModelData_PropertyTable_VoidVisitor):
79 def __init__(self):
80 super().__init__()
81 print("\nProperty table: ")
82
83 def VisitI32(self, theName: cadex.Base_UTF16String, theValue):
84 self.OutputData(theName, theValue)
85
86 def VisitDouble(self, theName: cadex.Base_UTF16String, theValue):
87 self.OutputData(theName, theValue)
88
90 self.OutputData(theName, theValue)
91
92 def OutputData(self, theName: cadex.Base_UTF16String, theValue):
93 print(f"{theName}: {theValue}")
94
95 def ExplorePropertyTable(self, thePT: cadex.ModelData_PropertyTable):
96
97 aPropVisitor = PropertyVisitor()
98 thePT.Accept(aPropVisitor)
99
100class SubShapePropertiesVisitor(cadex.ModelData_BRepRepresentation_SubshapeVisitor):
101 def __init__(self, theBRep: cadex.ModelData_BRepRepresentation):
102 super().__init__()
103 self.myPTList = []
104 self.myBRep = theBRep
105
106 def PropertyTables(self) -> list:
107 return self.myPTList
108
109 def VisitShape(self, theShape: cadex.ModelData_Shape):
110 aPT = self.myBRep.PropertyTable(theShape)
111 self.myPTList.append(aPT)
112
113
114def main(theSource: str):
115 aKey = license.Value()
116
117 if not cadex.LicenseManager.Activate(aKey):
118 print("Failed to activate CAD Exchanger license.")
119 return 1
120
122
124 print("Failed to read the file " + theSource )
125 return 1
126
127 aVisitor = PropertiesVisitor()
128 aModel.AcceptElementVisitor(aVisitor)
129
130 print("Completed")
131 return 0
132
133if __name__ == "__main__":
134 if len(sys.argv) != 2:
135 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
136 print(" <input_file> is a name of the XML file to be read")
137 sys.exit(1)
138
139 aSource = os.path.abspath(sys.argv[1])
140 sys.exit(main(aSource))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33