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
42import typing
43
44class MeshReplacementVisitor(cadex.ModelData_Model_VoidElementVisitor):
45 def __init__(self):
46 super().__init__()
50
51 def VisitEnterInstance(self, theInstance: cadex.ModelData_Instance):
52 self.myInstances.append(theInstance)
53 return True
54
55 def VisitLeaveInstance(self, theInstance: cadex.ModelData_Instance):
56 self.myInstances.pop()
57
58 def VisitPart(self, thePart: cadex.ModelData_Part):
59 if thePart.BRepRepresentation().IsNull():
60 return
61
62 if self.myReplacedParts.get(thePart) and len(self.myInstances) > 0:
63 self.myInstances[-1].SetReference(self.myReplacedParts[thePart])
64 return
65
67 aNewPart.SetAppearance(thePart.Appearance())
68 aNewPart.AddProperties(thePart.Properties())
69 aNewPart.AddPMI(thePart.PMI())
70 for anIt in thePart.GetLayerIterator():
71 aNewPart.AddToLayer(anIt)
72
75 aMesher.Compute(aNewPart)
76
77 if len(self.myInstances) == 0:
78 self.myRootReplacements[thePart] = aNewPart
79 else:
80 self.myRootReplacements[thePart] = aNewPart
81 self.myInstances[-1].SetReference(aNewPart)
82
83
84def main(theSource: str, theDest: str):
85 aKey = license.Value()
86
87 if not cadex.LicenseManager.Activate(aKey):
88 print("Failed to activate CAD Exchanger license.")
89 return 1
90
93
94 print("Conversion started...")
95
97 print("Failed to open and convert the file " + theSource)
98 return 1
99
100 aVisitor = MeshReplacementVisitor()
101 aModel.AcceptElementVisitor(aVisitor)
103 for aRoot in aModel.GetElementIterator():
105 aRootPart = cadex.ModelData_Part.Cast(aRoot)
106 assert aVisitor.myRootReplacements.get(aRootPart), "Part was not processed"
107 aNewRoots.append(aVisitor.myRootReplacements[aRootPart])
108 else:
109 aNewRoots.append(aRoot)
110
111 aModel.Clear()
112 for aNewRoot in aNewRoots:
113 aModel.AddRoot(aNewRoot)
114
116
118 print("Failed to convert and write the file to specified format " + theDest)
119 return 1
120
121 print("Completed")
122 return 0
123
124if __name__ == "__main__":
125 if len(sys.argv) != 3:
126 print(" <input_file> is a name of the SLD file to be read")
127 print(" <output_file> is a name of the VRML file to Save() the model")
128 sys.exit(1)
129
130 aSource = os.path.abspath(sys.argv[1])
131 aDest = os.path.abspath(sys.argv[2])
132
133 sys.exit(main(aSource, aDest))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Computes a polygonal representation from a B-Rep one.
Definition: ModelAlgo_BRepMesher.hxx:48
Defines parameters used by the B-Rep mesher.
Definition: ModelAlgo_BRepMesherParameters.hxx:33
Defines an occurrence of assembly or part in a scene graph.
Definition: ModelData_Instance.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
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:35
static IdType GetTypeId()
Definition: ModelData_Part.cxx:270
Base class for part, instance and assembly.
Definition: ModelData_SceneGraphElement.hxx:39