1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 # Creation of a box using the end-user API
22 # Author: Daniel Brunier-Coulin
23 # -----------------------------
25 from salome.shaper import model
26 from salome.shaper import geom
32 mypartset = model.moduleDocument()
37 mypart = model.addPart(mypartset).document()
40 # Creating the base of the box
42 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
45 p2 = geom.Pnt2d(0, 25)
46 p3 = geom.Pnt2d(25, 25)
47 p4 = geom.Pnt2d(25, 0)
49 line = model.addPolygon(mybase, p1, p2, p3, p4)
51 mybase.setParallel(line[0], line[2])
52 mybase.setParallel(line[1], line[3])
53 mybase.setPerpendicular(line[0], line[3])
55 mybase.setVertical(line[0])
56 mybase.setFixed(line[0].startPoint())
58 mywidth = mybase.setLength(line[0], 50)
59 mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
62 # Creating the extrusion
64 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
68 # Creating a cylinder on a face of the box
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"
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)
80 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
83 # Subtracting the cylinder to the box
85 model.addCut(mypart, mybox.results(), myboss.results())
92 mybase.setValue(mylength, 100)
97 assert(model.checkPythonDump())