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
41import math
42
44 aVector = theVector.Normalized()
46
47def MakeCircularFace(thePos: cadex.ModelData_Point,
54 aFace.Append(aWire)
55 return aFace
56
57def MakeCircularFaceWithInnerWire(thePos: cadex.ModelData_Point,
64
67 aFace.Append(anInner)
68 aFace.Append(anOuter)
69 return aFace
70
71def MakeCylindricalFace(thePos: cadex.ModelData_Point,
74 theLength: float):
78
79 theTopEdge = None
80 theBottomEdge = None
81
82 aWire = aFace.OuterWire()
83 anIt = cadex.ModelData_Shape_Iterator(aWire, cadex.ModelData_ST_Edge)
84 while anIt.HasNext():
86 aP1 = anEdge.EndVertex().Point()
87 aP2 = anEdge.StartVertex().Point()
89
90 if aP1.Z() == (theLength * theDir.Z()):
91 theTopEdge = anEdge
92 else:
93 theBottomEdge = anEdge
94
95 return aFace, theTopEdge, theBottomEdge
96
97
99 aNutA = theRadius * 2
100 aNutB = theRadius * 1.5
101 aHeight = theRadius / 2
102
106
109
114
116
117
120
122 aBRep.SetAppearance(aNutShape, anApp)
123
125 return aNut
126
128 aMajorRadius = theRadius * 1.3
129 aLongLength = theRadius * 6
130 aShortLength = theRadius / 2
131
132
133
135 aMajorRadius, aShortLength)
136
138 theRadius, aLongLength)
139
140
143
144
148
149
152
154 aShell.Append(aFace2)
155 aShell.Append(aFace3)
156 aShell.Append(aFace4)
157 aShell.Append(aFace5)
158
160
161
164
166 aBRep.SetAppearance(aSolid, anApp)
167
169 return aBolt
170
171def CreateNutBoltAssembly(theNut: cadex.ModelData_Part,
176
178 aNutBoltAssembly.AddInstance(theNut, aNutTrsf)
179 aNutBoltAssembly.AddInstance(theBolt, aBoltTrsf)
180 return aNutBoltAssembly
181
182
183def main():
184 aKey = license.Value()
185
186 if not cadex.LicenseManager.Activate(aKey):
187 print("Failed to activate CAD Exchanger license.")
188 return 1
189
190
191 aRadius = 0.8
192
196
197
198 aNut = CreateNut(aRadius)
199 aBolt = CreateBolt(aRadius)
200
201
202 aNutBoltAssembly = CreateNutBoltAssembly(aNut, aBolt, -aRadius * 4.5)
203
204
206
207
208 for i in range(len(aPos)):
211 aModel.AddRoot(anInstance)
212
215
216 print("Completed")
217 return 0
218
219if __name__ == "__main__":
220 sys.exit(main())
221
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
static ModelData_Shape CreateExtrusion(const ModelData_Shape &theShape, const ModelData_Vector &theVec)
Creates an extrusion body.
Definition: ModelAlgo_BRepFeatures.cxx:84
Provides an interface to appearance which is a collection of visual styles.
Definition: ModelData_Appearance.hxx:39
Defines a group of scene graph element.
Definition: ModelData_Assembly.hxx:33
Defines a right-hand axis placement in 3D.
Definition: ModelData_Axis2Placement.hxx:38
Defines a right-handed or left-handed axis placement in 3D.
Definition: ModelData_Axis3Placement.hxx:38
Defines precise Boundary Representation of part.
Definition: ModelData_BRepRepresentation.hxx:39
Defines 3D circle.
Definition: ModelData_Circle.hxx:33
Defines an RGBA color (with alpha channel).
Definition: ModelData_Color.hxx:34
Defines a cylindrical surface.
Definition: ModelData_CylindricalSurface.hxx:32
Defines a 3D direction.
Definition: ModelData_Direction.hxx:180
static const ModelData_Direction & ZDir()
Definition: ModelData_Direction.cxx:108
static const ModelData_Direction & XDir()
Definition: ModelData_Direction.cxx:96
Defines an edge.
Definition: ModelData_Edge.hxx:36
static const ModelData_Edge & Cast(const ModelData_Shape &theShape)
Casts a base class object to ModelData_Edge.
Definition: ModelData_Edge.cxx:688
Defines a topological face.
Definition: ModelData_Face.hxx:32
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
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 plane.
Definition: ModelData_Plane.hxx:32
Defines a 3D point.
Definition: ModelData_Point.hxx:295
Defines a connected set of faces.
Definition: ModelData_Shell.hxx:31
Defines a topological solid.
Definition: ModelData_Solid.hxx:31
Defines a 3D vector.
Definition: ModelData_Vector.hxx:442
Defines topological vertex.
Definition: ModelData_Vertex.hxx:31
Defines a connected set of edges.
Definition: ModelData_Wire.hxx:31
static const ModelData_Wire & Cast(const ModelData_Shape &theShape)
Definition: ModelData_Wire.cxx:88