2 from GeomDataAPI import *
5 # Initialization of the Sketch
6 # ----------------------------
9 return modelAPI_CompositeFeature( doc.addFeature("Sketch") )
12 def setXOYPlane(sketch):
13 geomDataAPI_Point( sketch.attribute("Origin") ).setValue(0, 0, 0)
14 geomDataAPI_Dir( sketch.attribute("DirX") ).setValue(1, 0, 0)
15 geomDataAPI_Dir( sketch.attribute("DirY") ).setValue(0, 1, 0)
16 geomDataAPI_Dir( sketch.attribute("Norm") ).setValue(0, 0, 1)
22 def addPoint(x, y, sketch):
23 point = sketch.addFeature("SketchPoint")
24 geomDataAPI_Point2D( point.attribute("PointCoordindates") ).setValue(x, y)
25 point.execute() #Required to get the result, if needed for creating constraints
29 def getGeometry(point):
30 return geomDataAPI_Point2D( point.attribute("PointCoordindates") )
36 def addClosedBrokenLine(coords, sketch):
40 l1 = sketch.addFeature("SketchLine")
41 geomDataAPI_Point2D( l1.attribute("StartPoint") ).setValue(c0.x(), c0.y())
42 geomDataAPI_Point2D( l1.attribute("EndPoint") ).setValue(c1.x(), c1.y())
48 l2 = sketch.addFeature("SketchLine")
49 geomDataAPI_Point2D( l2.attribute("StartPoint") ).setValue(c1.x(), c1.y())
50 geomDataAPI_Point2D( l2.attribute("EndPoint") ).setValue(c2.x(), c2.y())
53 constraint = sketch.addFeature("SketchConstraintCoincidence")
54 constraint.refattr("ConstraintEntityA").setAttr( l1.attribute("EndPoint") )
55 constraint.refattr("ConstraintEntityB").setAttr( l2.attribute("StartPoint") )
60 l2 = sketch.addFeature("SketchLine")
61 geomDataAPI_Point2D( l2.attribute("StartPoint") ).setValue(c1.x(), c1.y())
62 geomDataAPI_Point2D( l2.attribute("EndPoint") ).setValue(c0.x(), c0.y())
65 constraint = sketch.addFeature("SketchConstraintCoincidence")
66 constraint.refattr("ConstraintEntityA").setAttr( l1.attribute("EndPoint") )
67 constraint.refattr("ConstraintEntityB").setAttr( l2.attribute("StartPoint") )
69 constraint = sketch.addFeature("SketchConstraintCoincidence")
70 constraint.refattr("ConstraintEntityA").setAttr( l2.attribute("EndPoint") )
71 constraint.refattr("ConstraintEntityB").setAttr( l0.attribute("StartPoint") )
76 def addLine(x1, y1, x2, y2, sketch):
77 line = sketch.addFeature("SketchLine")
78 geomDataAPI_Point2D( line.attribute("StartPoint") ).setValue(x1, y1)
79 geomDataAPI_Point2D( line.attribute("EndPoint") ).setValue(x2, y2)
80 line.execute() #Required to get the result, if needed for creating constraints
84 def getGeometry(line):
85 return modelAPI_ResultConstruction(line.firstResult())
88 def getStartPoint(line):
89 return geomDataAPI_Point2D( line.attribute("StartPoint") )
92 def getEndPoint(line):
93 return geomDataAPI_Point2D( line.attribute("EndPoint") )
99 def makeCoincident(p1, p2, sketch):
100 constraint = sketch.addFeature("SketchConstraintCoincidence")
101 constraint.refattr("ConstraintEntityA").setAttr(p1)
102 constraint.refattr("ConstraintEntityB").setAttr(p2)
105 def makeParallel(l1, l2, sketch):
106 constraint = sketch.addFeature("SketchConstraintParallel")
107 constraint.refattr("ConstraintEntityA").setObject(l1)
108 constraint.refattr("ConstraintEntityB").setObject(l2)
111 def makePerpendicular(l1, l2, sketch):
112 constraint = sketch.addFeature("SketchConstraintPerpendicular")
113 constraint.refattr("ConstraintEntityA").setObject(l1)
114 constraint.refattr("ConstraintEntityB").setObject(l2)
116 def makeConstantLength(line, length, sketch):
117 constraint = sketch.addFeature("SketchConstraintLength")
118 constraint.refattr("ConstraintEntityA").setObject(line)
119 constraint.real("ConstraintValue").setValue(length)