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", str(L))
27 model.addParameter(part, "E", str(E))
28 model.addParameter(part, "P", str(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 = model.addPolygon(sketch, *geom_points)
39 sketch.setFixed(left.startPoint())
41 sketch.setHorizontal(bottom)
42 sketch.setHorizontal(top)
44 sketch.setVertical(right)
45 sketch.setVertical(left)
47 sketch.setLength(top, "L")
48 sketch.setLength(left, "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_3")
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 = model.addPolygon(sketch, *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, True)
80 sketch.setParallel(left, right)
81 sketch.setParallel(left, v2)
82 sketch.setParallel(bottom, h1)
83 sketch.setParallel(top, h2)
85 sketch.setPerpendicular(left, bottom)
86 sketch.setPerpendicular(left, top)
88 sketch.setEqual(top, bottom)
89 sketch.setEqual(h1, h2)
91 sketch.setCoincident(arc.center(), v1)
92 sketch.setCoincident(arc.startPoint(), h2.endPoint())
93 sketch.setCoincident(arc.endPoint(), h1.startPoint())
96 left_e = sketch.addLine("Extrusion_1_1/Generated_Face_3&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, 16)
104 sketch.setLength(h2, 20)
105 sketch.setLength(right, 16)
106 sketch.setLength(top, "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, = model.addPolygon(sketch, *geom_points)
128 points = [(l + r, H), (l + 2 * r, H), (l, 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, False)
134 top_middle.setAuxiliary(True)
137 sketch.setParallel(bottom, top_left)
138 sketch.setParallel(bottom, top_right)
140 sketch.setPerpendicular(bottom, left)
141 sketch.setPerpendicular(bottom, right)
143 sketch.setEqual(left, right)
145 sketch.setLength(bottom, L)
146 sketch.setLength(right, H)
147 sketch.setLength(top_left, l)
149 sketch.setCoincident(top_middle, arc.center())
150 sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
151 sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
153 sketch.setRadius(arc, r)
156 bottom_e = sketch.addLine("Boolean_1_1/Modified_5&Boolean_1_1/Modified_8")
157 sketch.setCoincident(bottom_e, 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 = model.addPolygon(sketch, *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.addFuse(part, b1.result() + b2.result())
205 boolean = model.addFuse(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.addFuse(part, boolean.result() + b4.result())
222 assert(model.checkPythonDump())