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 RemovedSGEFinder(cadex.ModelData_Model_VoidElementVisitor):
44
45
46 def __init__(self, theNameToRemove: cadex.Base_UTF16String):
47 super().__init__()
48 self.myNameToRemove = theNameToRemove
49 self.SGEsToRemove = {}
50
51
52
53
54 def VisitEnterAssembly(self, theElement: cadex.ModelData_Assembly) -> bool:
55 for aSGE in cadex.ModelData_Model_ElementIterator(theElement):
56 aChild = cadex.ModelData_Instance.Cast(aSGE)
57
58 if aChild.Reference() and aChild.Reference().Name() == self.myNameToRemove:
59 self.RemoveElement(aChild, theElement)
60
61 return True
62
64 if self.SGEsToRemove.get(theParent):
65 self.SGEsToRemove[theParent].append(theElement)
66 else:
67 self.SGEsToRemove[theParent] = [theElement]
68
69def main(theSource: str, theOutput: str, theNameToRemove: str):
70 aKey = license.Value()
71
72 if not cadex.LicenseManager.Activate(aKey):
73 print("Failed to activate CAD Exchanger license.")
74 return 1
75
76
78
80 print("Failed to read the file " + theSource)
81 return 1
82
83
84 aRootsToRemove = []
85 for anElement in cadex.ModelData_Model_ElementIterator(aModel):
87 aRootsToRemove.append(anElement)
88
89 for aRootToRemove in aRootsToRemove:
90 aModel.RemoveRoot(aRootToRemove)
91
92
94 aModel.AcceptElementVisitor(aFinder)
95
96
97 for aParent in aFinder.SGEsToRemove:
98 aChildrenToRemove = aFinder.SGEsToRemove[aParent]
99
100 for aChildToRemove in aChildrenToRemove:
101 aParent.RemoveInstance(aChildToRemove)
102
103
105
106 print("Completed")
107
108if __name__ == "__main__":
109 if len(sys.argv) != 4:
110 print("Usage: " + os.path.abspath(Path(__file__).resolve()) +
111 " <input_file> <output_file> <sge_to_remove>, where:")
112 print(" <input_file> is a name of the XML file to be read")
113 print(" <output_file> is a name of the CDX file where the output should be stored")
114 print(" <sge_to_remove> is a name of the scene graph elements to remove")
115 sys.exit(1)
116
117 aSource = sys.argv[1]
118 anOutput = sys.argv[2]
119 aNameToRemove = sys.argv[3]
120
121 sys.exit(main(aSource, anOutput, aNameToRemove))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Defines a group of scene graph element.
Definition: ModelData_Assembly.hxx:33
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33