Salome HOME
updated copyright message
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick2.py
1 # Copyright (C) 2014-2023  CEA, EDF
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # Creation of a box using the end-user API
21 # Author: Daniel Brunier-Coulin
22 # -----------------------------
23
24 from salome.shaper import model
25 from salome.shaper import geom
26
27
28 # Initialisation
29
30 model.begin()
31 mypartset = model.moduleDocument()
32
33
34 # Creating a new Part
35
36 mypart = model.addPart(mypartset).document()
37
38
39 # Creating the base of the box
40
41 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
42
43 p1 = geom.Pnt2d(0, 0)
44 p2 = geom.Pnt2d(0, 25)
45 p3 = geom.Pnt2d(25, 25)
46 p4 = geom.Pnt2d(25, 0)
47
48 line = model.addPolygon(mybase, p1, p2, p3, p4)
49
50 mybase.setParallel(line[0], line[2])
51 mybase.setParallel(line[1], line[3])
52 mybase.setPerpendicular(line[0], line[3])
53
54 mybase.setVertical(line[0])
55 mybase.setFixed(line[0].startPoint())
56
57 mywidth = mybase.setLength(line[0], 50)
58 mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
59 model.do()
60
61 # Creating the extrusion
62
63 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
64 model.do()
65
66
67 # Creating a cylinder on a face of the box
68
69 thisface = "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2"
70 thisxmin = "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1]"
71 thiszmax = "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/To_Face]"
72
73 mystand = model.addSketch(mypart, thisface)
74 circle = mystand.addCircle(0, 25, 5)
75 mystand.setDistance(circle.center(), mystand.addLine(thisxmin), 10)
76 mystand.setDistance(circle.center(), mystand.addLine(thiszmax), 10)
77 model.do()
78
79 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
80 model.do()
81
82 # Subtracting the cylinder to the box
83
84 model.addCut(mypart, mybox.results(), myboss.results())
85 model.end()
86
87
88 # Editing the box
89
90 model.begin()
91 mybase.setValue(mylength, 100)
92 model.do()
93 mybox.setSize(40)
94 model.end()
95
96 assert(model.checkPythonDump())