Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick2.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 # Creation of a box using the end-user API
22 # Author: Daniel Brunier-Coulin
23 # -----------------------------
24
25 from salome.shaper import model
26 from salome.shaper import geom
27
28
29 # Initialisation
30
31 model.begin()
32 mypartset = model.moduleDocument()
33
34
35 # Creating a new Part
36
37 mypart = model.addPart(mypartset).document()
38
39
40 # Creating the base of the box
41
42 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
43
44 p1 = geom.Pnt2d(0, 0)
45 p2 = geom.Pnt2d(0, 25)
46 p3 = geom.Pnt2d(25, 25)
47 p4 = geom.Pnt2d(25, 0)
48
49 line = model.addPolygon(mybase, p1, p2, p3, p4)
50
51 mybase.setParallel(line[0], line[2])
52 mybase.setParallel(line[1], line[3])
53 mybase.setPerpendicular(line[0], line[3])
54
55 mybase.setVertical(line[0])
56 mybase.setFixed(line[0].startPoint())
57
58 mywidth = mybase.setLength(line[0], 50)
59 mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
60 model.do()
61
62 # Creating the extrusion
63
64 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
65 model.do()
66
67
68 # Creating a cylinder on a face of the box
69
70 thisface = "Extrusion_1_1/Generated_Face_2"
71 thisxmin = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1"
72 thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1"
73
74 mystand = model.addSketch(mypart, thisface)
75 circle = mystand.addCircle(0, 25, 5)
76 mystand.setDistance(circle.center(), mystand.addLine(thisxmin), 10)
77 mystand.setDistance(circle.center(), mystand.addLine(thiszmax), 10)
78 model.do()
79
80 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
81 model.do()
82
83 # Subtracting the cylinder to the box
84
85 model.addCut(mypart, mybox.results(), myboss.results())
86 model.end()
87
88
89 # Editing the box
90
91 model.begin()
92 mybase.setValue(mylength, 100)
93 model.do()
94 mybox.setSize(40)
95 model.end()
96
97 assert(model.checkPythonDump())