Salome HOME
Added support of python high level API addons proposed by DBC as test of this approach.
[modules/shaper.git] / src / PythonAPI / MakeBrick2.py
1 # Creation of a box using the end-user API
2 # Author: Daniel Brunier-Coulin
3 # -----------------------------
4
5 import modeler
6 import geom
7
8
9 # Initialisation
10
11 modeler.begin()
12 mypartset = modeler.moduleDocument()
13
14
15 # Creating a new Part
16
17 mypart = modeler.addPart(mypartset).document()
18
19
20 # Creating the base of the box
21
22 mybase = modeler.addSketch( mypart, modeler.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].startPointData(),line[2].result(), 50 )
37
38
39 # Creating the extrusion
40
41 mybox = modeler.addExtrusion( mypart, mybase.selectFace(), 50 )
42
43
44 # Creating a cylinder on a face of the box
45
46 thisface = "Extrusion_1/LateralFace_2"
47 thisxmin = "Extrusion_1/LateralFace_3|Extrusion_1/LateralFace_2"
48 thiszmax = "Extrusion_1/LateralFace_2|Extrusion_1/TopFace_1"
49
50 mystand = modeler.addSketch( mypart, thisface )
51 circle  = mystand.addCircle( 0, 25, 5)
52 mystand.setDistance( circle.centerData(), thisxmin, 10 )
53 mystand.setDistance( circle.centerData(), thiszmax, 10 )
54
55 myboss = modeler.addExtrusion( mypart, mystand.selectFace(), -5 )
56
57
58 # Subtracting the cylinder to the box
59
60 modeler.addSubtraction( mypart, mybox.result(), myboss.result() )
61 modeler.end()
62
63
64 # Editing the box
65
66 modeler.begin()
67 mybase.setValue( mylength, 100 )
68 mybox.setSize( 20 )
69 modeler.end()