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. 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 window pops up, allowing you to quickly autocomplete the rest of the line. Let's start by creating a new empty document: If this is your first time using Python, consider reading this short introduction to Python programming before going any 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 errors you make while typing. In the console, you write Python commands one by one, which are executed when you press return, while 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 ( View → Panels → Python Console), or from the Macro editor ( 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 find yourself learning some of the 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 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 (if the option to Show script commands in Python console is enabled in Edit → Preferences → Python → Macro) and executed. FreeCAD has an advanced Python console, available from menu View → Panels → Python console. Some FreeCAD workbenches and most of the addon workbenches are fully programmed in Python. For example, you can 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. This make it a valuable tool to learn, as you will be able to use it in other software, such as Blender, Inkscape or GRASS.įreeCAD makes extensive use of Python. It has a series of features that make it suitable for us FreeCAD users: It is very easy to learn, especially for people who had never programmed before, and it is embedded in many other applications. Python is a popular, open source programming language, very often embedded in applications as a scripting language, as is the case with FreeCAD.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |