Salome HOME
ecbcb43cdf32cb60a75378047b861f681f787cfa
[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 from salome.shaper import model
6 from salome.shaper 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, 25)
26 p3 = geom.Pnt2d(25, 25)
27 p4 = geom.Pnt2d(25, 0)
28
29 line = model.addPolygon(mybase, p1, p2, p3, p4)
30
31 mybase.setParallel(line[0], line[2])
32 mybase.setParallel(line[1], line[3])
33 mybase.setPerpendicular(line[0], line[3])
34
35 mybase.setVertical(line[0])
36 mybase.setFixed(line[0].startPoint())
37
38 mywidth = mybase.setLength(line[0], 50)
39 mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
40 model.do()
41
42 # Creating the extrusion
43
44 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
45 model.do()
46
47
48 # Creating a cylinder on a face of the box
49
50 thisface = "Extrusion_1_1/Generated_Face_2"
51 thisxmin = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1"
52 thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1"
53
54 mystand = model.addSketch(mypart, thisface)
55 circle = mystand.addCircle(0, 25, 5)
56 mystand.setDistance(circle.center(), mystand.addLine(thisxmin), 10)
57 mystand.setDistance(circle.center(), mystand.addLine(thiszmax), 10)
58 model.do()
59
60 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
61 model.do()
62
63 # Subtracting the cylinder to the box
64
65 model.addCut(mypart, mybox.results(), myboss.results())
66 model.end()
67
68
69 # Editing the box
70
71 model.begin()
72 mybase.setValue(mylength, 100)
73 model.do()
74 mybox.setSize(40)
75 model.end()
76
77 assert(model.checkPythonDump())