1 # Creation of a box using the end-user API
2 # Author: Daniel Brunier-Coulin
3 # -----------------------------
12 mypartset = modeler.moduleDocument()
17 mypart = modeler.addPart(mypartset).document()
20 # Creating the base of the box
22 mybase = modeler.addSketch( mypart, modeler.defaultPlane("XOY") )
24 p1 = geom.Pnt2d( 0, 0 )
25 p2 = geom.Pnt2d( 0, 1 )
26 p3 = geom.Pnt2d( 1, 1 )
27 p4 = geom.Pnt2d( 1, 0 )
29 line = mybase.addPolygon(p1, p2, p3, p4)
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() )
35 mywidth = mybase.setLength( line[0].result(), 50 )
36 mylength = mybase.setDistance( line[0].startPointData(),line[2].result(), 50 )
39 # Creating the extrusion
41 mybox = modeler.addExtrusion( mypart, mybase.selectFace(), 50 )
44 # Creating a cylinder on a face of the box
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"
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 )
55 myboss = modeler.addExtrusion( mypart, mystand.selectFace(), -5 )
58 # Subtracting the cylinder to the box
60 modeler.addSubtraction( mypart, mybox.result(), myboss.result() )
67 mybase.setValue( mylength, 100 )