Salome HOME
Changed "From" and "To" face naming in Extrusion and Revolution
[modules/shaper.git] / src / PythonAPI / examples / Platine.py
1 # Creation of Platine model using the end-user API
2 # Author: Sergey POKHODENKO
3 # -----------------------------
4
5 import geom
6 import model
7
8 # Initialisation
9 model.begin()
10 partset = model.moduleDocument()
11
12 # Create a new Part
13 part = model.addPart(partset).document()
14
15 L = 64
16 E = 16
17 P = 80
18
19 # Create Parameters
20 model.addParameter(part, "L", L)
21 model.addParameter(part, "E", E)
22 model.addParameter(part, "P", P)
23
24 def vertical_body():
25     # Create YOZ sketch
26     sketch = model.addSketch(part, model.defaultPlane("YOZ"))
27
28     points = [(0, 0), (0, L), (L, L), (L, 0)]
29     geom_points = [geom.Pnt2d(*p) for p in points]
30     left, top, right, bottom = sketch.addPolygon(*geom_points)
31
32     # Set constraints
33     sketch.setRigid(left.startPoint())
34
35     sketch.setHorizontal(bottom.result())
36     sketch.setHorizontal(top.result())
37
38     sketch.setVertical(right.result())
39     sketch.setVertical(left.result())
40
41     sketch.setLength(top.result(), "L")
42     sketch.setLength(left.result(), "L")
43
44     sketch.setFillet(left.endPoint(), 32)
45
46     model.do()  #!!!
47
48     # Create extrusion
49     body = model.addExtrusion(part, sketch.selectFace(), "E")
50
51     model.do()
52
53     return body
54
55 def bottom_body():
56     # Create XOY sketch
57     sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_4")
58
59     # Create base polygon
60     points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
61     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
62     geom_points = [geom.Pnt2d(*p) for p in points]
63     left, top, v2, h2, v1, h1, right, bottom = sketch.addPolygon(*geom_points)
64
65     points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 16)]
66     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
67     center, start, end = [geom.Pnt2d(*p) for p in points]
68     arc = sketch.addArc(center, start, end, inversed=True)
69
70     # Set Auxiliarity
71     v1.setAuxiliary(True)
72
73     # Set constraints
74     sketch.setParallel(left.result(), right.result())
75     sketch.setParallel(left.result(), v2.result())
76     sketch.setParallel(bottom.result(), h1.result())
77     sketch.setParallel(top.result(), h2.result())
78
79     sketch.setPerpendicular(left.result(), bottom.result())
80     sketch.setPerpendicular(left.result(), top.result())
81
82     sketch.setEqual(top.result(), bottom.result())
83     sketch.setEqual(h1.result(), h2.result())
84
85     sketch.setCoincident(arc.center(), v1.result())
86     sketch.setCoincident(arc.startPoint(), h2.endPoint())
87     sketch.setCoincident(arc.endPoint(), h1.startPoint())
88
89     # Binding
90     left_e = sketch.addLine("Extrusion_1_1/LateralFace_4&Extrusion_1_1/ToFace_1_1")
91     sketch.setCoincident(left_e.startPoint(), left.endPoint())
92     sketch.setCoincident(left_e.endPoint(), left.startPoint())
93
94     model.do()  #!!!
95
96     # Dimensions
97     sketch.setLength(v1.result(), 16)
98     sketch.setLength(h2.result(), 20)
99     sketch.setLength(right.result(), 16)
100     sketch.setLength(top.result(), "P")
101     model.do()
102
103     # Create extrusion
104     body = model.addExtrusion(part, sketch.selectFace(), "-E")
105
106     model.do()
107
108     return body
109
110 def body_3():
111     # Create XOZ sketch
112     sketch = model.addSketch(part, "Boolean_1_1/Modified_4")
113
114     # Create base polygon
115     H, L, l, r = 28, 40, 8, 12
116
117     points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
118     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
119     geom_points = [geom.Pnt2d(*p) for p in points]
120     left, top_left, top_middle, top_right, right, bottom, = sketch.addPolygon(*geom_points)
121
122     points = [(l + r, H), (l, H), (l + 2 * r, H)]
123     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
124     center, start, end = [geom.Pnt2d(*p) for p in points]
125     arc = sketch.addArc(center, start, end)
126
127     # Set Auxiliarity
128     top_middle.setAuxiliary(True)
129
130     # Set constraints
131     sketch.setParallel(bottom.result(), top_left.result())
132     sketch.setParallel(bottom.result(), top_right.result())
133
134     sketch.setPerpendicular(bottom.result(), left.result())
135     sketch.setPerpendicular(bottom.result(), right.result())
136
137     sketch.setEqual(left.result(), right.result())
138
139     sketch.setLength(bottom.result(), L)
140     sketch.setLength(right.result(), H)
141     sketch.setLength(top_left.result(), l)
142
143     sketch.setCoincident(top_middle.result(), arc.center())
144     sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
145     sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
146
147     sketch.setRadius(arc.result(), r)
148
149     # Binding
150     bottom_e = sketch.addLine("Boolean_1_1/Modified_5&Boolean_1_1/Modified_8")
151     sketch.setCoincident(bottom_e.result(), bottom.startPoint())
152     sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
153
154     model.do()  #!!!
155
156     # Create extrusion
157     body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
158
159     model.do()  #!!!
160
161     return body
162
163 def body_4():
164     # Create XOZ 2nd sketch
165     sketch = model.addSketch(part, "Boolean_2_1/Modified_4")
166
167     # Create base polygon
168     points = [(0, 0), (0, 1), (1, 0)]
169     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
170     geom_points = [geom.Pnt2d(*p) for p in points]
171     left, diagonal, bottom = sketch.addPolygon(*geom_points)
172
173     # Binding
174     bottom_e = sketch.addLine("Boolean_2_1/Modified_3&Boolean_2_1/Modified_4")
175     sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
176     sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
177
178     left_e = sketch.addLine("Boolean_2_1/Modified_6&Boolean_2_1/Modified_8")
179     sketch.setCoincident(left_e.startPoint(), left.endPoint())
180
181     model.do()  #!!!
182
183     # Create extrusion
184     body = model.addExtrusion(part, sketch.selectFace(), "-12")
185
186     model.do()  #!!!
187
188     return body
189
190
191 b1 = vertical_body()
192 b2 = bottom_body()
193
194 boolean = model.addAddition(part, b1.result() + b2.result())
195 model.do()
196
197 b3 = body_3()
198
199 boolean = model.addAddition(part, boolean.result() + b3.result())
200 model.do()
201
202 b4 = body_4()
203
204 boolean = model.addAddition(part, boolean.result() + b4.result())
205 model.do()