Salome HOME
f47ba3f705d9d9726a21d3d2383fa96d39049d84
[modules/shaper.git] / src / PythonFeaturesPlugin / FeaturesAPI.py
1 from ModelAPI import *
2 from GeomDataAPI import *
3 from GeomAlgoAPI import *
4
5 # NOTE : I think this style should be chosen
6 # for function as recommended by Python programming
7 # standards
8
9
10 def build_face_from_sketch(sketch, edges=None):
11     # If no edges have been selected, get the whole sketch
12     # edges
13     if edges == None:
14         result = sketch.firstResult()
15         edges = modelAPI_ResultConstruction(result).shape()
16
17     # Build the face
18     origin = geomDataAPI_Point(sketch.attribute("Origin")).pnt()
19     dirX = geomDataAPI_Dir(sketch.attribute("DirX")).dir()
20     dirY = geomDataAPI_Dir(sketch.attribute("DirY")).dir()
21     normal = geomDataAPI_Dir(sketch.attribute("Norm")).dir()
22     faces = ShapeList()
23     GeomAlgoAPI_SketchBuilder.createFaces(
24         origin, dirX, dirY, normal, edges, faces)
25     return faces[0]
26
27 # NOTE : with an optional argument it is not
28 # a so good idea to put part as last argument
29 # it would result in a mandatory argument
30 # put after an optionnal one
31
32
33 def addExtrusion(part, sketch, size, reverse=False, subshapes=None):
34     feature = part.addFeature("Extrusion")
35
36     # Build apropriate face
37     face = build_face_from_sketch(sketch, subshapes)
38     # Get sketch result
39     sketchResult = sketch.firstResult()
40
41     # Set attributes and execute the feature
42     feature.selection("extrusion_face").setValue(sketchResult, face)
43     feature.real("extrusion_size").setValue(size)
44     feature.boolean("extrusion_reverse").setValue(False)
45     feature.execute()
46
47     return feature