Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick1.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
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 l1 = mybase.addLine(0, 0, 0, 25)
44 l2 = mybase.addLine(0, 25, 25, 25)
45 l3 = mybase.addLine(25, 25, 25, 0)
46 l4 = mybase.addLine(25, 0, 0, 0)
47
48 mybase.setCoincident(l1.endPoint(), l2.startPoint())
49 mybase.setCoincident(l2.endPoint(), l3.startPoint())
50 mybase.setCoincident(l3.endPoint(), l4.startPoint())
51 mybase.setCoincident(l4.endPoint(), l1.startPoint())
52
53 mybase.setParallel(l1, l3)
54 mybase.setParallel(l2, l4)
55
56 mybase.setPerpendicular(l1, l4)
57
58 mybase.setVertical(l1)
59 mybase.setFixed(l1.startPoint())
60
61 mywidth = mybase.setLength(l1, 50)
62 mylength = mybase.setDistance(l1.startPoint(), l3, 50)
63 model.do()
64
65 # Creating the extrusion
66
67 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
68 model.do()
69
70 # Creating a cylinder on a face of the box
71
72 thisface = "Extrusion_1_1/Generated_Face_2"
73 thisxmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1"
74 thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1"
75
76 mystand = model.addSketch(mypart, thisface)
77
78 c1 = mystand.addCircle(0, 25, 5)
79 l1 = mystand.addLine(thisxmax)
80 l2 = mystand.addLine(thiszmax)
81 model.do()
82 mystand.setDistance(c1.center(), l1, 10)
83 mystand.setDistance(c1.center(), l2, 10)
84 model.do()
85
86
87 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
88 model.do()
89
90 # Subtracting the cylinder to the box
91
92 model.addCut(mypart, mybox.results(), myboss.results())
93 model.end()
94
95
96 # Editing the box
97
98 model.begin()
99 mybase.setValue(mylength, 100)
100 model.do()
101 mybox.setSize(80)
102 model.end()
103
104 assert(model.checkPythonDump())