]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonFeaturesPlugin/FeaturesAPI.py
Salome HOME
feef52528b6a757a377c499b049fbb8cca45e2a2
[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 def build_face_from_sketch (sketch, edges=None) :
9   # If no edges have been selected, get the whole sketch 
10   # edges
11   if edges == None:
12     result = sketch.firstResult()
13     edges  = modelAPI_ResultConstruction(result).shape()
14   
15   # Build the face
16   origin = geomDataAPI_Point( sketch.attribute("Origin") ).pnt()
17   dirX   = geomDataAPI_Dir( sketch.attribute("DirX") ).dir()
18   dirY   = geomDataAPI_Dir( sketch.attribute("DirY") ).dir()
19   normal = geomDataAPI_Dir( sketch.attribute("Norm") ).dir()
20   faces  = ShapeList()
21   GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, dirY, normal, edges, faces)
22   return faces[0]
23
24 # NOTE : with an optional argument it is not
25 # a so good idea to put part as last argument
26 # it would result in a mandatory argument
27 # put after an optionnal one
28 def addExtrusion(part, sketch, size, reverse=False, subshapes=None):
29   feature = part.addFeature("Extrusion")
30   
31   # Build apropriate face
32   face = build_face_from_sketch(sketch, subshapes)
33   # Get sketch result
34   sketchResult = sketch.firstResult()
35   
36   # Set attributes and execute the feature
37   feature.selection("extrusion_face").setValue(sketchResult, face)
38   feature.real("extrusion_size").setValue(size)
39   feature.boolean("extrusion_reverse").setValue(False)
40   feature.execute()
41   
42   return feature