Salome HOME
Updated copyright comment
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick1.py
1 # Copyright (C) 2014-2024  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
26
27 # Initialisation
28
29 model.begin()
30 mypartset = model.moduleDocument()
31
32
33 # Creating a new Part
34
35 mypart = model.addPart(mypartset).document()
36
37
38 # Creating the base of the box
39
40 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
41
42 l1 = mybase.addLine(0, 0, 0, 25)
43 l2 = mybase.addLine(0, 25, 25, 25)
44 l3 = mybase.addLine(25, 25, 25, 0)
45 l4 = mybase.addLine(25, 0, 0, 0)
46
47 mybase.setCoincident(l1.endPoint(), l2.startPoint())
48 mybase.setCoincident(l2.endPoint(), l3.startPoint())
49 mybase.setCoincident(l3.endPoint(), l4.startPoint())
50 mybase.setCoincident(l4.endPoint(), l1.startPoint())
51
52 mybase.setParallel(l1, l3)
53 mybase.setParallel(l2, l4)
54
55 mybase.setPerpendicular(l1, l4)
56
57 mybase.setVertical(l1)
58 mybase.setFixed(l1.startPoint())
59
60 mywidth = mybase.setLength(l1, 50)
61 mylength = mybase.setDistance(l1.startPoint(), l3, 50)
62 model.do()
63
64 # Creating the extrusion
65
66 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
67 model.do()
68
69 # Creating a cylinder on a face of the box
70
71 thisface = "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2"
72 thisxmax = "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1]"
73 thiszmax = "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/To_Face]"
74
75 mystand = model.addSketch(mypart, thisface)
76
77 c1 = mystand.addCircle(0, 25, 5)
78 l1 = mystand.addLine(thisxmax)
79 l2 = mystand.addLine(thiszmax)
80 model.do()
81 mystand.setDistance(c1.center(), l1, 10)
82 mystand.setDistance(c1.center(), l2, 10)
83 model.do()
84
85
86 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
87 model.do()
88
89 # Subtracting the cylinder to the box
90
91 model.addCut(mypart, mybox.results(), myboss.results())
92 model.end()
93
94
95 # Editing the box
96
97 model.begin()
98 mybase.setValue(mylength, 100)
99 model.do()
100 mybox.setSize(80)
101 model.end()
102
103 assert(model.checkPythonDump())