]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/examples/MakeBrick2.py
Salome HOME
[PythonAPI] Remove the word shaper from some places in PythonAPI
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick2.py
1 # Creation of a box using the end-user API
2 # Author: Daniel Brunier-Coulin
3 # -----------------------------
4
5 import model
6 import geom
7
8
9 # Initialisation
10
11 model.begin()
12 mypartset = model.moduleDocument()
13
14
15 # Creating a new Part
16
17 mypart = model.addPart(mypartset).document()
18
19
20 # Creating the base of the box
21
22 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
23
24 p1 = geom.Pnt2d(0, 0)
25 p2 = geom.Pnt2d(0, 1)
26 p3 = geom.Pnt2d(1, 1)
27 p4 = geom.Pnt2d(1, 0)
28
29 line = mybase.addPolygon(p1, p2, p3, p4)
30
31 mybase.setParallel(line[0].result(), line[2].result())
32 mybase.setParallel(line[1].result(), line[3].result())
33 mybase.setPerpendicular(line[0].result(), line[3].result())
34
35 mywidth = mybase.setLength(line[0].result(), 50)
36 mylength = mybase.setDistance(line[0].startPoint(), line[2].result(), 50)
37
38
39 # Creating the extrusion
40
41 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
42
43
44 # Creating a cylinder on a face of the box
45
46 thisface = "Extrusion_1_1/LateralFace_2"
47 thisxmin = "Extrusion_1_1/LateralFace_3|Extrusion_1_1/LateralFace_2"
48 thiszmax = "Extrusion_1_1/LateralFace_2|Extrusion_1_1/ToFace_1"
49
50 mystand = model.addSketch(mypart, thisface)
51 circle = mystand.addCircle(0, 25, 5)
52 mystand.setDistance(circle.center(), thisxmin, 10)
53 mystand.setDistance(circle.center(), thiszmax, 10)
54
55 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
56
57
58 # Subtracting the cylinder to the box
59
60 model.addSubtraction(mypart, mybox.result(), myboss.result())
61 model.end()
62
63
64 # Editing the box
65
66 model.begin()
67 mybase.setValue(mylength, 100)
68 mybox.setSize(20)
69 model.end()