
- #MAC FREECAD MACROS TUTORIAL CODE#
- #MAC FREECAD MACROS TUTORIAL SERIES#
- #MAC FREECAD MACROS TUTORIAL WINDOWS#
You'll immediately see a couple of very interesting things such as: Now let's explore the contents of our box: You can get a list of all possible object types like Part::Box:
#MAC FREECAD MACROS TUTORIAL CODE#
If you turned on the "show script commands in Python console" option above, try now adding a sphere with the appropriate button in the Part Workbench, and you will see the multiple lines of Python code being executed one after the other. Many of the toolbar buttons that add objects in FreeCAD actually do two things: add the object, and recompute. We must do that manually, whenever we need: Our box is added in the tree view, but nothing happens in the 3D view yet, because when working from Python, the document is never recomputed automatically. Let's use one of the methods to add a new object to our document:

Names that begin with an underscore are usually there for the internal working of the module, and you shouldn't care about them. Usually names that begin with a capital letter are attributes, they contain a value, while names that begin with small letter are functions (also called methods), they "do something". Let's see what we can do with it:Įxplore the available options. The parentheses are mandatory when you are calling a Python function, such as this one. If you would add a dot after newDocument, instead of the parentheses, it would show you everything that is contained inside the newDocument function. The window that pops up therefore shows you everything that is contained inside "FreeCAD". In Python, the dot is used to indicate something that is contained inside something else (newDocument is a function that is inside the FreeCAD module). This is similar to pressing the "new document" button on the toolbar. Before choosing "newDocument", have a look at the other options available.Īs soon as you press Enter our new document will be created. This makes it very easy to explore the functionality available. Even better, each entry in the autocomplete list has a tooltip explaining what it does.
#MAC FREECAD MACROS TUTORIAL WINDOWS#
If you type this in the FreeCAD Python console, you will notice that as soon as you type "FreeCAD." (the word FreeCAD followed by a dot), a windows pops up, allowing to quickly autocomplete the rest of your line. Let's start by creating a new empty document: If this is the first time you are coding in Python, consider reading this short Introduction to Python before going further, it will make the basic concepts of Python clearer. In this chapter, you will be able to use both methods, but it is highly recommended to use the Python Console, since it will immediately inform you of any typing error. In the console, you write Python commands one by one, which are executed when you press return, while the macros can contain a more complex script made of several lines, which is executed only when the macro is launched from the same Macros window. There are two easy ways to write Python code in FreeCAD: From the Python console (menu View -> Panels -> Python Console), or from the Macro editor (menu Tools -> Macros -> New). If you are interested in learning more, the FreeCAD documentation wiki has an extensive section related to Python programming. In this chapter, we will discover very generally the Python language. This system also uses the Python console, by simply recording everything that is done in it. By leaving the Python console open, you can literally see the Python code unfold as you work, and in no time, almost without knowing it, you will be learning some Python language.įreeCAD also has a macros system, which allows you to record actions to be replayed later. It is often useful to perform operations for which there is no toolbar button yet, or to check shapes for problems, or to perform repetitive tasks:īut the Python console also has another very important use: Every time you press a toolbar button, or perform other operations in FreeCAD, some Python code is printed in the console and executed. FreeCAD has an advanced Python console, available from menu View->Panels->Python console. Some workbenches of FreeCAD and most of the addon workbenches are fully programmed in Python. You can, for example, create new objects, modify their geometry, analyze their contents, or even create new interface controls, tools and panels. With it, you can access and control almost any feature of FreeCAD. You will be able to use it in many other applications, such as Blender, Inkscape or GRASS.įreeCAD makes extensive use of Python. It is embedded in many other applications, which makes it a very valuable tool to learn.
#MAC FREECAD MACROS TUTORIAL SERIES#
It also has a series of features that makes it specially interesting for us FreeCAD users: It is very easy to learn, specially for people who have never programmed before. Python is a widely popular, open-source programming language, very often used as a scripting language, embedded in applications, as is the case with FreeCAD.
