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
42def NumberOfTriangles(thePoly: cadex.ModelData_PolyRepresentation) -> int:
43 trianglesNB = 0
44
45 aList = thePoly.Get()
46 for aPVS in aList:
48 anITS = cadex.ModelData_IndexedTriangleSet.Cast(aPVS)
49 trianglesNB += anITS.NumberOfFaces()
50 return trianglesNB
51
56 return aBRep
57
58def AddPolyToPart(thePart: cadex.ModelData_Part, theLOD):
59 aBRep = thePart.BRepRepresentation()
62
63 aPoly = aMesher.Compute(aBRep)
64
65 thePart.AddRepresentation(aPoly)
66 print(f"A polygonal representation with {NumberOfTriangles(aPoly)} triangles has been added");
67
68
69def main():
70 aKey = license.Value()
71
72 if not cadex.LicenseManager.Activate(aKey):
73 print("Failed to activate CAD Exchanger license.")
74 return 1
75
78
79 AddPolyToPart(aPart, cadex.ModelAlgo_BRepMesherParameters.Coarse)
80 AddPolyToPart(aPart, cadex.ModelAlgo_BRepMesherParameters.Medium)
81 AddPolyToPart(aPart, cadex.ModelAlgo_BRepMesherParameters.Fine)
82
84 aModel.AddRoot(aPart)
85
87 print("Unable to save the model")
88 return 1
89
90 print("Completed")
91 return 0
92
93if __name__ == "__main__":
94 sys.exit(main())
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
static ModelData_Solid CreateSphere(double theRadius, double theU=2 *M_PI, double theVmin=-M_PI_2, double theVmax=M_PI_2)
Creates a sphere.
Definition: ModelAlgo_TopoPrimitives.cxx:148
Defines precise Boundary Representation of part.
Definition: ModelData_BRepRepresentation.hxx:39
static ModelData_Body Create(const ModelData_Shape &theShape)
Creates a body from an arbitrary shape.
Definition: ModelData_Body.cxx:223
static IdType GetTypeId()
Definition: ModelData_IndexedTriangleSet.cxx:134
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
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
Defines a 3D point.
Definition: ModelData_Point.hxx:295