Python

From FreeCAD Documentation
Revision as of 20:12, 26 October 2018 by Vocx (talk | contribs) (Created page with "[https://www.python.org Python] is a general purpose, high level programming language that very commonly is embedded in large applications to automate some tasks by creating s...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Python is a general purpose, high level programming language that very commonly is embedded in large applications to automate some tasks by creating scripts or macros.

In FreeCAD, Python code can be used to create various elements programmatically, without needing the graphical user interface. Additionally, many tools and workbenches of FreeCAD are programmed in Python.

When writing Python code, it's advisable to follow PEP8: Style Guide for Python Code.

Conventions

In this wiki, some conventions for Python examples should be followed.

This is a typical function

Wire = makeWire(pointslist, closed=False, placement=None, face=None, support=None)
  • Python indicates optional arguments by providing a default value with key-value pairs. This means that any of the following calls are valid
Wire = makeWire(pointslist)
Wire = makeWire(pointslist, False)
Wire = makeWire(pointslist, False, None)
Wire = makeWire(pointslist, False, None, None)
Wire = makeWire(pointslist, False, None, None, None)
  • The arguments

import FreeCAD, Draft

In particular, parentheses should immediately follow the function name, and a space should follow a comma. This makes the code more readable.