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")
61 sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face_3")
64 points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
65 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
66 geom_points = [geom.Pnt2d(*p) for p in points]
67 left, top, v2, h2, v1, h1, right, bottom = model.addPolygon(sketch, *geom_points)
69 points = [(P - 20, 16 + 16 / 2), (P - 20, 16 + 16), (P - 20, 16)]
70 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
71 center, start, end = [geom.Pnt2d(*p) for p in points]
72 arc = sketch.addArc(center, start, end, True)
78 sketch.setParallel(left, right)
79 sketch.setParallel(left, v2)
80 sketch.setParallel(bottom, h1)
81 sketch.setParallel(top, h2)
83 sketch.setPerpendicular(left, bottom)
84 sketch.setPerpendicular(left, top)
86 sketch.setEqual(top, bottom)
87 sketch.setEqual(h1, h2)
89 sketch.setCoincident(arc.center(), v1)
90 sketch.setCoincident(arc.startPoint(), h2.endPoint())
91 sketch.setCoincident(arc.endPoint(), h1.startPoint())
94 left_e = sketch.addLine("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/To_Face_1_1")
95 sketch.setCoincident(left_e.startPoint(), left.endPoint())
96 sketch.setCoincident(left_e.endPoint(), left.startPoint())
99 #sketch.setLength(v1, 16)
100 sketch.setLength(v2, 32)
101 sketch.setLength(h2, 20)
102 sketch.setLength(right, 16)
103 sketch.setLength(top, "P")
107 body = model.addExtrusion(part, sketch.selectFace(), "-E")
115 sketch = model.addSketch(part, "Boolean_1_1/Modified_4")
117 # Create base polygon
118 H, L, l, r = 28, 40, 8, 12
120 points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
121 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
122 geom_points = [geom.Pnt2d(*p) for p in points]
123 left, top_left, top_middle, top_right, right, bottom, = model.addPolygon(sketch, *geom_points)
125 points = [(l + r, H), (l + 2 * r, H), (l, H)]
126 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
127 center, start, end = [geom.Pnt2d(*p) for p in points]
128 arc = sketch.addArc(center, start, end, False)
131 top_middle.setAuxiliary(True)
134 sketch.setParallel(bottom, top_left)
135 sketch.setParallel(bottom, top_right)
137 sketch.setPerpendicular(bottom, left)
138 sketch.setPerpendicular(bottom, right)
140 sketch.setEqual(left, right)
142 sketch.setLength(bottom, L)
143 sketch.setLength(right, H)
144 sketch.setLength(top_left, l)
146 sketch.setCoincident(top_middle, arc.center())
147 sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
148 sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
150 sketch.setRadius(arc, r)
153 bottom_e = sketch.addLine("Boolean_1_1/Modified_5&Boolean_1_1/Modified_8")
154 sketch.setCoincident(bottom_e, bottom.startPoint())
155 sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
160 body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
165 # Create XOZ 2nd sketch
166 sketch = model.addSketch(part, "Boolean_2_1/Modified_4")
168 # Create base polygon
169 points = [(0, 0), (0, 1), (1, 0)]
170 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
171 geom_points = [geom.Pnt2d(*p) for p in points]
172 left, diagonal, bottom = model.addPolygon(sketch, *geom_points)
175 bottom_e = sketch.addLine("Boolean_2_1/Modified_3&Boolean_2_1/Modified_4")
176 sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
177 sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
179 left_e = sketch.addLine("Boolean_2_1/Modified_6&Boolean_2_1/Modified_8")
180 sketch.setCoincident(left_e.startPoint(), left.endPoint())
185 body = model.addExtrusion(part, sketch.selectFace(), "-12")
193 boolean = model.addFuse(part, b1.results() + b2.results())
198 boolean = model.addFuse(part, boolean.results() + b3.results())
201 # START DEBUG PURPOSES
202 # prepare a study without last operation to trap floating problem with degenerated line
203 #aPathToStore = os.path.join(os.getcwd(), "Data")
205 #if not os.path.exists(aPathToStore):
206 # os.mkdir(aPathToStore)
207 #results = ModelAPI.StringList()
208 #ModelAPI.ModelAPI_Session.get().save(aPathToStore, results)
212 boolean = model.addFuse(part, boolean.results() + b4.results())
215 assert(model.checkPythonDump())