14.5.1 Sketch polyline
This function is responsible for constructing the sketch by adding line segments between consecutive points in the list of coordinates. Importantly, it ensures the proper alignment of these line segments by employing Coincident constraints.
def sketch_polyline(sketch,points):
freecad_version = int(FreeCAD.Version()[2])
if freecad_version >= 18:
partline = Part.LineSegment
else:
partline = Part.Line
for index in range(len(points)-1):
sketch.addGeometry(partline(FreeCAD.Vector(points[index][0],points[index][1], 0), FreeCAD.Vector(
if index>0:
sketch.addConstraint(Sketcher.Constraint(’Coincident’,index-1,2,index,1))
sketch.addGeometry(partline(FreeCAD.Vector(points[index+1][0],points[index+1][1],0),FreeCAD.Vector(
sketch.addConstraint(Sketcher.Constraint(’Coincident’,index,2,index+1,1))
sketch.addConstraint(Sketcher.Constraint(’Coincident’,index+1,2,0,1))
This function does not create dimensional constraints, which means that changing the values of QW-Parameters in GUI will not result in redrawing the sketch - reexecuting the script is necessary. The list of points must not contain duplicates.