1 # Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 # Creation of a box using the end-user API
21 # Author: Daniel Brunier-Coulin
22 # -----------------------------
24 from salome.shaper import model
25 from salome.shaper import geom
31 mypartset = model.moduleDocument()
36 mypart = model.addPart(mypartset).document()
39 # Creating the base of the box
41 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
44 p2 = geom.Pnt2d(0, 25)
45 p3 = geom.Pnt2d(25, 25)
46 p4 = geom.Pnt2d(25, 0)
48 line = model.addPolygon(mybase, p1, p2, p3, p4)
50 mybase.setParallel(line[0], line[2])
51 mybase.setParallel(line[1], line[3])
52 mybase.setPerpendicular(line[0], line[3])
54 mybase.setVertical(line[0])
55 mybase.setFixed(line[0].startPoint())
57 mywidth = mybase.setLength(line[0], 50)
58 mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
61 # Creating the extrusion
63 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
67 # Creating a cylinder on a face of the box
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]"
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)
79 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
82 # Subtracting the cylinder to the box
84 model.addCut(mypart, mybox.results(), myboss.results())
91 mybase.setValue(mylength, 100)
96 assert(model.checkPythonDump())