Salome HOME
Added python dump checking for every unit test where it is useful.
[modules/shaper.git] / src / PythonAPI / examples / MakeBrick1.py
1 # Creation of a box using the end-user API
2 # Author: Daniel Brunier-Coulin
3 # -----------------------------
4
5 import model
6
7
8 # Initialisation
9
10 model.begin()
11 mypartset = model.moduleDocument()
12
13
14 # Creating a new Part
15
16 mypart = model.addPart(mypartset).document()
17
18
19 # Creating the base of the box
20
21 mybase = model.addSketch(mypart, model.defaultPlane("XOY"))
22
23 l1 = mybase.addLine(0, 0, 0, 1)
24 l2 = mybase.addLine(0, 1, 1, 1)
25 l3 = mybase.addLine(1, 1, 1, 0)
26 l4 = mybase.addLine(1, 0, 0, 0)
27
28 mybase.setCoincident(l1.endPoint(), l2.startPoint())
29 mybase.setCoincident(l2.endPoint(), l3.startPoint())
30 mybase.setCoincident(l3.endPoint(), l4.startPoint())
31 mybase.setCoincident(l4.endPoint(), l1.startPoint())
32
33 mybase.setParallel(l1, l3)
34 mybase.setParallel(l2, l4)
35
36 mybase.setPerpendicular(l1, l4)
37
38 mywidth = mybase.setLength(l1, 50)
39 mylength = mybase.setDistance(l1.startPoint(), l3, 50)
40
41 # Creating the extrusion
42
43 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
44
45 # Creating a cylinder on a face of the box
46
47 thisface = "Extrusion_1_1/Generated_Face_2"
48 thisxmin = "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2"
49 thisxmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1"
50 thiszmin = "Sketch_1/Edge5_1"
51 thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1"
52
53 mystand = model.addSketch(mypart, thisface)
54
55 c1 = mystand.addCircle(0, 25, 5)
56 mystand.setDistance(c1.center(), mystand.addLine(thisxmin), 10)
57 mystand.setDistance(c1.center(), mystand.addLine(thiszmax), 10)
58
59
60 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
61
62 # Subtracting the cylinder to the box
63
64 model.addCut(mypart, mybox.result(), myboss.result())
65 model.end()
66
67
68 # Editing the box
69
70 model.begin()
71 mybase.setValue(mylength, 100)
72 mybox.setSize(80)
73 model.end()
74
75 assert(model.checkPythonDump())