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
10 def build_face_from_sketch(sketch, edges=None):
11 # If no edges have been selected, get the whole sketch
14 result = sketch.firstResult()
15 edges = modelAPI_ResultConstruction(result).shape()
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()
23 GeomAlgoAPI_SketchBuilder.createFaces(
24 origin, dirX, dirY, normal, edges, faces)
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
33 def addExtrusion(part, sketch, size, reverse=False, subshapes=None):
34 feature = part.addFeature("Extrusion")
36 # Build apropriate face
37 face = build_face_from_sketch(sketch, subshapes)
39 sketchResult = sketch.firstResult()
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)