File size: 1,021 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # SPDX-License-Identifier: LGPL-2.1-or-later
# Example how to use the basic sketcher tools
from Sketcher import *
from Part import *
from FreeCAD import *
import FreeCAD as App
# set some constances for the constraints
StartPoint = 1
EndPoint = 2
MiddlePoint = 3
# create a document and a Sketch object
if App.activeDocument() is None:
App.newDocument()
f = App.activeDocument().addObject("Sketcher::SketchObject", "Sketch")
# add geometry to the sketch
f.Geometry = [
LineSegment(Vector(0, 0, 0), Vector(2, 20, 0)),
LineSegment(Vector(0, 0, 0), Vector(20, 2, 0)),
]
# add constraints to the sketch
f.Constraints = [Constraint("Vertical", 0), Constraint("Horizontal", 1)]
# recompute (solving) the sketch
App.activeDocument().recompute()
# add another constraint to tie the start points together
l = f.Constraints
l.append(Constraint("Coincident", 0, StartPoint, 1, StartPoint))
f.Constraints = l
# again recompute
App.activeDocument().recompute()
f.Geometry
|