2 from GeomDataAPI import *
3 from GeomAlgoAPI import *
5 # NOTE : I think this style should be chosen
6 # for function as recommended by Python programming
8 def build_face_from_sketch (sketch, edges=None) :
9 # If no edges have been selected, get the whole sketch
12 result = sketch.firstResult()
13 edges = modelAPI_ResultConstruction(result).shape()
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()
21 GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, dirY, normal, edges, faces)
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")
31 # Build apropriate face
32 face = build_face_from_sketch(sketch, subshapes)
34 sketchResult = sketch.firstResult()
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)