1 # Creation of Platine model using the end-user API
2 # Author: Sergey POKHODENKO
3 # -----------------------------
16 partset = model.moduleDocument()
19 part = model.addPart(partset).document()
26 model.addParameter(part, "L", L)
27 model.addParameter(part, "E", E)
28 model.addParameter(part, "P", P)
32 sketch = model.addSketch(part, model.defaultPlane("YOZ"))
34 points = [(0, 0), (0, L), (L, L), (L, 0)]
35 geom_points = [geom.Pnt2d(*p) for p in points]
36 left, top, right, bottom = sketch.addPolygon(*geom_points)
39 sketch.setRigid(left.startPoint())
41 sketch.setHorizontal(bottom.result())
42 sketch.setHorizontal(top.result())
44 sketch.setVertical(right.result())
45 sketch.setVertical(left.result())
47 sketch.setLength(top.result(), "L")
48 sketch.setLength(left.result(), "L")
50 sketch.setFillet(left.endPoint(), 32)
55 body = model.addExtrusion(part, sketch.selectFace(), "E")
63 sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face_4")
66 points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
67 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
68 geom_points = [geom.Pnt2d(*p) for p in points]
69 left, top, v2, h2, v1, h1, right, bottom = sketch.addPolygon(*geom_points)
71 points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 16)]
72 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
73 center, start, end = [geom.Pnt2d(*p) for p in points]
74 arc = sketch.addArc(center, start, end, inversed=True)
80 sketch.setParallel(left.result(), right.result())
81 sketch.setParallel(left.result(), v2.result())
82 sketch.setParallel(bottom.result(), h1.result())
83 sketch.setParallel(top.result(), h2.result())
85 sketch.setPerpendicular(left.result(), bottom.result())
86 sketch.setPerpendicular(left.result(), top.result())
88 sketch.setEqual(top.result(), bottom.result())
89 sketch.setEqual(h1.result(), h2.result())
91 sketch.setCoincident(arc.center(), v1.result())
92 sketch.setCoincident(arc.startPoint(), h2.endPoint())
93 sketch.setCoincident(arc.endPoint(), h1.startPoint())
96 left_e = sketch.addLine("Extrusion_1_1/Generated_Face_4&Extrusion_1_1/To_Face_1_1")
97 sketch.setCoincident(left_e.startPoint(), left.endPoint())
98 sketch.setCoincident(left_e.endPoint(), left.startPoint())
103 sketch.setLength(v1.result(), 16)
104 sketch.setLength(h2.result(), 20)
105 sketch.setLength(right.result(), 16)
106 sketch.setLength(top.result(), "P")
110 body = model.addExtrusion(part, sketch.selectFace(), "-E")
118 sketch = model.addSketch(part, "Boolean_1_1/Modified_4")
120 # Create base polygon
121 H, L, l, r = 28, 40, 8, 12
123 points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
124 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
125 geom_points = [geom.Pnt2d(*p) for p in points]
126 left, top_left, top_middle, top_right, right, bottom, = sketch.addPolygon(*geom_points)
128 points = [(l + r, H), (l, H), (l + 2 * r, H)]
129 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
130 center, start, end = [geom.Pnt2d(*p) for p in points]
131 arc = sketch.addArc(center, start, end)
134 top_middle.setAuxiliary(True)
137 sketch.setParallel(bottom.result(), top_left.result())
138 sketch.setParallel(bottom.result(), top_right.result())
140 sketch.setPerpendicular(bottom.result(), left.result())
141 sketch.setPerpendicular(bottom.result(), right.result())
143 sketch.setEqual(left.result(), right.result())
145 sketch.setLength(bottom.result(), L)
146 sketch.setLength(right.result(), H)
147 sketch.setLength(top_left.result(), l)
149 sketch.setCoincident(top_middle.result(), arc.center())
150 sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
151 sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
153 sketch.setRadius(arc.result(), r)
156 bottom_e = sketch.addLine("Boolean_1_1/Modified_5&Boolean_1_1/Modified_8")
157 sketch.setCoincident(bottom_e.result(), bottom.startPoint())
158 sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
163 body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
170 # Create XOZ 2nd sketch
171 sketch = model.addSketch(part, "Boolean_2_1/Modified_4")
173 # Create base polygon
174 points = [(0, 0), (0, 1), (1, 0)]
175 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
176 geom_points = [geom.Pnt2d(*p) for p in points]
177 left, diagonal, bottom = sketch.addPolygon(*geom_points)
180 bottom_e = sketch.addLine("Boolean_2_1/Modified_3&Boolean_2_1/Modified_4")
181 sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
182 sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
184 left_e = sketch.addLine("Boolean_2_1/Modified_6&Boolean_2_1/Modified_8")
185 sketch.setCoincident(left_e.startPoint(), left.endPoint())
190 body = model.addExtrusion(part, sketch.selectFace(), "-12")
200 boolean = model.addAddition(part, b1.result() + b2.result())
205 boolean = model.addAddition(part, boolean.result() + b3.result())
208 # START DEBUG PURPOSES
209 # prepare a study without last operation to trap floating problem with degenerated line
210 aPathToStore = os.path.join(os.getcwd(), "Data")
212 if not os.path.exists(aPathToStore):
213 os.mkdir(aPathToStore)
214 results = ModelAPI.StringList()
215 ModelAPI.ModelAPI_Session.get().save(aPathToStore, results)
219 boolean = model.addAddition(part, boolean.result() + b4.result())