Adding or modifying constraints with Python (Become an expert)

In addition to using the Sketcher interactively and graphically we can use Python to program it automatically.

Getting ready

For this recipe, we need the Python console open. In the menu bar, open View, then Views, and then make sure that Python console is checked.

How to do it...

  1. Enter the following code block into the console:
     from Sketcher import * import Part import FreeCAD as App from FreeCAD import Vector if(App.activeDocument() == None):App.newDocument() f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch") f.addGeometry(Part.Line(Vector(0,0,0),Vector(2,20,0))) f.addGeometry(Part.Line(Vector(0,0,0),Vector(20,2,0))) f.Constraints = [Constraint('Vertical',0),\ Constraint('Horizontal',1)] ...

Get FreeCAD [How-to] now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.