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 # Required to get the result, if needed for creating constraints
30 def getGeometry(point):
31 return geomDataAPI_Point2D(point.attribute("PointCoordindates"))
37 def addClosedBrokenLine(coords, sketch):
41 l1 = sketch.addFeature("SketchLine")
42 geomDataAPI_Point2D(l1.attribute("StartPoint")).setValue(c0.x(), c0.y())
43 geomDataAPI_Point2D(l1.attribute("EndPoint")).setValue(c1.x(), c1.y())
49 l2 = sketch.addFeature("SketchLine")
51 l2.attribute("StartPoint")).setValue(c1.x(), c1.y())
52 geomDataAPI_Point2D(l2.attribute("EndPoint")).setValue(c2.x(), c2.y())
55 constraint = sketch.addFeature("SketchConstraintCoincidence")
56 constraint.refattr("ConstraintEntityA").setAttr(
57 l1.attribute("EndPoint"))
58 constraint.refattr("ConstraintEntityB").setAttr(
59 l2.attribute("StartPoint"))
64 l2 = sketch.addFeature("SketchLine")
66 l2.attribute("StartPoint")).setValue(c1.x(), c1.y())
67 geomDataAPI_Point2D(l2.attribute("EndPoint")).setValue(c0.x(), c0.y())
70 constraint = sketch.addFeature("SketchConstraintCoincidence")
71 constraint.refattr("ConstraintEntityA").setAttr(
72 l1.attribute("EndPoint"))
73 constraint.refattr("ConstraintEntityB").setAttr(
74 l2.attribute("StartPoint"))
76 constraint = sketch.addFeature("SketchConstraintCoincidence")
77 constraint.refattr("ConstraintEntityA").setAttr(
78 l2.attribute("EndPoint"))
79 constraint.refattr("ConstraintEntityB").setAttr(
80 l0.attribute("StartPoint"))
85 def addLine(x1, y1, x2, y2, sketch):
86 line = sketch.addFeature("SketchLine")
87 geomDataAPI_Point2D(line.attribute("StartPoint")).setValue(x1, y1)
88 geomDataAPI_Point2D(line.attribute("EndPoint")).setValue(x2, y2)
89 # Required to get the result, if needed for creating constraints
94 def getGeometry(line):
95 return modelAPI_ResultConstruction(line.firstResult())
98 def getStartPoint(line):
99 return geomDataAPI_Point2D(line.attribute("StartPoint"))
102 def getEndPoint(line):
103 return geomDataAPI_Point2D(line.attribute("EndPoint"))
109 def makeCoincident(p1, p2, sketch):
110 constraint = sketch.addFeature("SketchConstraintCoincidence")
111 constraint.refattr("ConstraintEntityA").setAttr(p1)
112 constraint.refattr("ConstraintEntityB").setAttr(p2)
116 def makeParallel(l1, l2, sketch):
117 constraint = sketch.addFeature("SketchConstraintParallel")
118 constraint.refattr("ConstraintEntityA").setObject(l1)
119 constraint.refattr("ConstraintEntityB").setObject(l2)
123 def makePerpendicular(l1, l2, sketch):
124 constraint = sketch.addFeature("SketchConstraintPerpendicular")
125 constraint.refattr("ConstraintEntityA").setObject(l1)
126 constraint.refattr("ConstraintEntityB").setObject(l2)
130 def makeConstantLength(line, length, sketch):
131 constraint = sketch.addFeature("SketchConstraintLength")
132 constraint.refattr("ConstraintEntityA").setObject(line)
133 constraint.real("ConstraintValue").setValue(length)