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
42
43class LayersFiller(cadex.ModelData_Model_CombinedElementVisitor):
44 def __init__(self):
45 super().__init__()
48
49 def VisitPart(self, thePart: cadex.ModelData_Part):
50 self.mySGELayer.Add(thePart)
51 aBRep = thePart.BRepRepresentation()
52 if aBRep:
53 aBodyList = aBRep.Get()
54 for aBody in aBodyList:
55 aBRep.AddToLayer(aBody, self.mySubShapesLayer)
56
57 def VisitEnterSGE(self, theElement) -> bool:
58 self.mySGELayer.Add(theElement)
59 return True
60
61
62class LayerItemVisitor(cadex.ModelData_Layer_ItemVisitor):
63 def __init__(self):
64 super().__init__()
65 self.myPartsNb = 0
66 self.myAssembliesNb = 0
67 self.myInstancesNb = 0
68 self.myShapesNb = 0
69
70 def GetElementsCount(self):
71 print(f"Number of parts: {self.myPartsNb}")
72 print(f"Number of assemblies: {self.myAssembliesNb}")
73 print(f"Number of instances: {self.myInstancesNb}")
74 print(f"Number of shapes: {self.myShapesNb}")
75
76 def VisitSGE(self, theSGE: cadex.ModelData_SceneGraphElement):
78 self.myPartsNb += 1
80 self.myAssembliesNb += 1
82 self.myInstancesNb += 1
83
85 self.myShapesNb += 1
86
87class LayersVisitor(cadex.ModelData_Model_LayerVisitor):
88 def __init__(self):
89 super().__init__()
90
91 def VisitLayer(self, theLayer: cadex.ModelData_Layer):
92 aLayerItemVisitor = LayerItemVisitor()
93 theLayer.Accept(aLayerItemVisitor)
94 print(f"Layer {theLayer.Name()} contains:")
95 aLayerItemVisitor.GetElementsCount()
96
97
98def main(theSource: str):
99 aKey = license.Value()
100
101 if not cadex.LicenseManager.Activate(aKey):
102 print("Failed to activate CAD Exchanger license.")
103 return 1
104
106
108 print("Failed to read the file " + theSource)
109 return 1
110
111 aLayerIt = aModel.GetLayerIterator()
112 if not aLayerIt.HasNext():
113
114 aVisitor = LayersFiller()
115 aModel.AcceptLayerVisitor(aVisitor)
116
117
118 aModel.AddLayer(aVisitor.mySGELayer)
119 aModel.AddLayer(aVisitor.mySubShapesLayer)
120
121 aLayerVisitor = LayersVisitor()
122 aModel.AcceptLayerVisitor(aLayerVisitor)
123
124 print("Completed")
125 return 0
126
127if __name__ == "__main__":
128 if len(sys.argv) != 2:
129 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
130 print(" <input_file> is a name of the XML file to be read")
131 sys.exit(1)
132
133 aSource = os.path.abspath(sys.argv[1])
134 sys.exit(main(aSource))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
static IdType GetTypeId()
Definition: ModelData_Assembly.cxx:82
static IdType GetTypeId()
Definition: ModelData_Instance.cxx:144
Provides a layer of objects.
Definition: ModelData_Layer.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
static IdType GetTypeId()
Definition: ModelData_Part.cxx:270
Base class of part representations.
Definition: ModelData_Representation.hxx:30