Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / doc / gui / General / tutorial.py
1 from SketchAPI import *
2
3 from salome.shaper import model
4
5 model.begin()
6 partSet = model.moduleDocument()
7 Part_1 = model.addPart(partSet)
8 Part_1_doc = Part_1.document()
9
10 # Parameters
11 model.addParameter(Part_1_doc, "h", "90", "nut height")
12 model.addParameter(Part_1_doc, "a", "115.4")
13
14 # Step1. Sketch.
15 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
16 SketchLine_1 = Sketch_1.addLine(-57.69999999999999, 99.93933159672423, 57.70000000000001, 99.93933159672423)
17 SketchLine_2 = Sketch_1.addLine(57.70000000000001, 99.93933159672423, 0, 0)
18 SketchLine_2.setAuxiliary(True)
19 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
20 SketchLine_3 = Sketch_1.addLine(0, 0, -57.69999999999999, 99.93933159672423)
21 SketchLine_3.setAuxiliary(True)
22 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
23 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
24 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
25 SketchPoint_1 = SketchProjection_1.createdFeature()
26 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
27 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
28 SketchLine_4 = SketchProjection_2.createdFeature()
29 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_4.result(), SketchLine_1.result())
30 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_1.result())
31 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_1.result())
32 SketchMultiRotation_1 = Sketch_1.addRotation([SketchLine_1.result()], SketchAPI_Line(SketchLine_4).startPoint(), 360, 6, True)
33 [SketchLine_5, SketchLine_6, SketchLine_7, SketchLine_8, SketchLine_9] = SketchMultiRotation_1.rotated()
34 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "a")
35 model.do()
36
37 # Step2. Polyline.
38 Point_2 = model.addPoint(Part_1_doc, 50, 0, 0)
39 Point_2.result().setColor(0, 0, 255)
40 Point_3 = model.addPoint(Part_1_doc, 80, 0, 0)
41 Point_3.result().setColor(0, 0, 255)
42 Point_4 = model.addPoint(Part_1_doc, 112, 0, 13)
43 Point_4.result().setColor(0, 0, 255)
44 Point_5 = model.addPoint(Part_1_doc, 112, 0, 48)
45 Point_5.result().setColor(0, 0, 255)
46 Point_6 = model.addPoint(Part_1_doc, 80, 0, 63)
47 Point_6.result().setColor(0, 0, 255)
48 Point_7 = model.addPoint(Part_1_doc, "80", "0", "h")
49 Point_7.result().setColor(0, 0, 255)
50 Point_8 = model.addPoint(Part_1_doc, "50", "0", "h")
51 Point_8.result().setColor(0, 0, 255)
52 Polyline_1_objects = [model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"),
53                       model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_4"),
54                       model.selection("VERTEX", "Point_5"), model.selection("VERTEX", "Point_6"),
55                       model.selection("VERTEX", "Point_7")]
56 Polyline_1 = model.addPolyline3D(Part_1_doc, Polyline_1_objects, True)
57
58 # Step3. Face.
59 Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Polyline_1_1")])
60
61 # Step4. Revolution.
62 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), 360, 0)
63
64 # Step5. Extrusion.
65 Wire = model.selection("WIRE", "Sketch_1/Face-SketchLine_5r-SketchLine_6r-SketchLine_7r-SketchLine_8r-SketchLine_9r-SketchLine_1r_wire")
66 To = model.selection("FACE", "Revolution_1_1/Generated_Face&Point_4/Point_4")
67 From = model.selection("FACE", "Revolution_1_1/Generated_Face&Point_1/Point_1")
68
69 Extrusion_1 = model.addExtrusion(Part_1_doc, [Wire], model.selection("EDGE", "PartSet/OZ"), To, 0, From, 0)
70
71 # Step6. Common.
72 Common_1 = model.addCommon(Part_1_doc, [model.selection("SOLID", "Revolution_1_1"), model.selection("SOLID", "Extrusion_1_1")])
73
74 # Step7. Fillet.
75 Fillet_1 = model.addFillet(Part_1_doc, [model.selection("EDGE", "[Revolution_1_1/Generated_Face&Point_6/Point_6][Common_1_1/Modified_Face&Point_7/Point_7]")], 10)
76
77 # Step8. Box.
78 Box_1 = model.addBox(Part_1_doc, 20, 120, 20)
79
80 # Step9. Translation.
81 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], -10, 20, 70)
82
83 # Step10. Angular Copy.
84 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OZ"), 6)
85
86 # Step11. Cut.
87 Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Fillet_1_1")], [model.selection("COMPOUND", "AngularCopy_1_1")])
88 Cut_1.result().setColor(255, 214, 0)
89
90 model.end()