How to install macros/de

Beschreibung
Diese Seite zeigt dir, wie du FreeCAD Makros installieren und benutzen kannst.

Makros sind Befehlssequenzen, die zur Ausführung einer komplexen Zeichenoperation verwendet werden. Makros sind Python Skripte, d.h. sie sind Textdateien, die mit einem Texteditor geschrieben und bearbeitet werden können.

Während Python Skripte normalerweise die Erweiterung haben, sollten FreeCAD Makros die Erweiterung  haben. Eine Sammlung von Makros, die von erfahrenen Anwendern geschrieben wurden, findest Du auf der Seite Makrozepte.

Siehe Einführung in Python, um mehr über die Programmiersprache Python zu erfahren, und dann Python Skript Tutorium und FreeCAD Skript Grundlagen, um das Schreiben von Makros zu erlernen.

Hier ist ein Video über Installieren von FreeCAD Makros in Ubuntu.

Werkzeugleiste
Aufzeichnen Beenden Makro Dialog ausführen Ausführen

Menü
Neben den Werkzeugen in der Werkzeugleiste sind auch die folgenden Funktionen im Menü verfügbar. Start Fehlersuche Stop Fehlersuche
 * Schritt über
 * Schritt in
 * Umschalten Haltepunkt

Makros Verzeichnis
Makros werden in einem bestimmten Ordner unter dem FreeCAD Benutzerverzeichnis erstellt. Dieses Verzeichnis kann im Makrodialog ausführen, oder im Einstellungseditor, über das Menü.

Heruntergeladene Makros sollten ebenfalls in diesem Verzeichnis abgelegt werden.

Standardverzeichnis
Makros können einfach kopiert werden in

wobei ein Verzeichnis der obersten Ebene ist, das von FreeCAD beim Start durchsucht wird.

Der könnte ein systemweites Verzeichnis sein, in diesem Fall wird das Makro für alle Benutzer installiert.
 * Unter Linux ist es normalerweise
 * Unter Windows ist es normalerweise
 * Unter Mac OSX ist es normalerweise

Der könnte das Verzeichnis eines bestimmten Benutzers sein.
 * Unter Linux ist es normalerweise
 * Unter Windows ist es normalerweise
 * Unter Mac OSX ist es normalerweise

Konfigurieren des Benutzerverzeichnisses
1. Öffne das Menü, um den Makrodialog ausführen.



2. Setze den entsprechenden.
 * Linux: normalerweise
 * Windows: normalerweise
 * MacOS: normalerweise



3. Navigiere zu diesem Verzeichnis auf deinem Computer.
 * Linux: Füge die Adresse in deinen Dateimanager ein, "Nautilus" oder andere. Eventuell musst du + drücken, um das versteckte Verzeichnis sichtbar zu machen.
 * Windows: Füge die Adresse in dein "Datei Suchprogramm" ein und bestätige.
 * MacOS: Suche den Ordner im "Finder" oder füge die Adresse in ein "Datei Suchprogramm" ein; merke dir das Vorsatzzeichen im "Datei Suchprogramm" für eine Datei auf der Festplatte.



4. Add macro files to this directory.
 * Linux: leave the file manager open, and bookmark the location for faster access.
 * Windows: leave open the file explorer.
 * MacOS: either leave a "Finder" window open, or bookmark the location in your "File explorer", or set up an "Alias" to point to it, or drag the folder into the "SideBar" of the "Finder" so it is there to use from other programs such as text editors.



Automatic method
Starting with FreeCAD 0.17, use the Addon Manager in to install a macro that has been included in the FreeCAD-macros repository.

In past versions of FreeCAD you could use two automated ways to install macros and other addons:
 * addons_installer.FCMacro: itself a macro, this was the precursor to the Addon Manager, and is hosted in the FreeCAD-addons repository. You don't need to use this tool in new installations of FreeCAD.
 * freecad-pluginloader: also a macro, it could be used to install new components to FreeCAD. It is no longer developed.

The recommended way to install addons, that is, external workbenches and macros, is the Addon Manager. However, you can still add macros to your system with the manual methods described in the following sections; this is useful if you are developing and testing your own code.

Manual method 1. Copy the code to the macro editor
For macros that are relatively small, 300 lines or less, the code can be copied and pasted directly into the FreeCAD macro editor.

We will use Macro Apothem Based Prism GUI as an example.

1. Go to the macro wiki page, which should be listed in Macros recipes.

If there is a custom icon download it; click on it with the right mouse button and select ; place the icon in the macros directory. This icon can be used as a shortcut for the macro in a custom toolbar. The default icon is.



2. In the macro page, select the code inside the or  sections, and copy it.

3. In FreeCAD, open the menu to open the Execute macro dialog.



4. Click.



5. Enter the macro name, here, and press.



6. The macro editor opens, showing the full path of the new macro.



7. Paste the code in the editor window, and then click the cross on the tab to close the window.



8. A window appears asking for confirmation to save the code; click on. You can also use + to save the file.

Restart FreeCAD to correctly register the new macro.



9. Open the menu again,, select the new macro and press.



10. The macro now runs. Fill in the fields with your values and click the button.



11. This macro should return an error if no document is active; other macros open a new document if none exists.

Create a new document with, and then repeat the previous steps to execute the macro.



12. Once an active document is available, the macro runs and creates an object.



13. You can open the macro in the editor again to run it or modify it. Go to, select the macro and press.



14. The macro can now be run with, or by clicking on the button in the toolbar.



Manual method 2. Add a macro file from a compressed .zip file
Some macros are too big that it's inconvenient to copy and paste them into the macro editor, or they cannot be hosted in the wiki. In this case, the code may be hosted somewhere else, in a Github repository, or in the FreeCAD forum. The code may also be compressed into a file, tarball, or other type of archive if it contains several files. If the code is distributed in this way, the archive should be extracted and the files placed in the macros directory.

We will use Macro screw maker as an example.

1. Download the compressed code from the forum, Screw Maker.

You need to use a decompressor to get the internal files.
 * For Windows you can use an application like 7-zip or L-Zarc or quickzip.
 * For Linux you can use a command from the terminal

2. Download the compressed archive with the macro code to a local folder.



3. Decompress the file in the folder.



4. The decompressor creates a new directory with the unpacked files.



5. Go inside the new directory, and copy or cut the macro file.



6. Go to the macro directory and paste the file there.



7. In FreeCAD, open the menu to open the Execute macro dialog.



8. Select the new macro and press.



9. The macro now runs. Select the desired options, and click the button.





Execute a macro in command line
Command line execute a macro (.FCMacro or .py)

on Windows

on Linux

Indentation errors
The white space at the beginning of the lines (indentation) in the Python programming language is very important, and an integral part of the code. An inappropriate space may cause the code to not run or present errors.

This section describes some errors that may be encountered when copying and pasting, and writing macro code.

A typical indentation error looks like this:

Example 1
If the code lacks any indentation, the code won't work. Class and function definitions, as well as control structures  should be followed by a block of indented code.

This error is possible if the user doesn't copy the code correctly, and all spaces are accidentally removed.



Indentation problem fixed.



If the code is selected, all lines should be highlighted all the way to the left edge, indicating that the lines are aligned.



Example 2
If an additional space is introduced at the beginning of all lines, the Python interpreter will fail and complain about unnecessary indentation. In this case, all lines need the initial space removed.



Example 3
Here the code has been copied from a forum thread by using the button. Apparently the selection is good.



However, when the selection is pasted into the macro editor, undesirable indentation seems to appear.



In this case, the initial spaces need to be removed. This can be done with a specialized text editor to quickly decrease the indentation of the lines.

In Windows, Notepad++ can perform selection with + Mouse dragging, and then use.



Example 4
Here the selection also selects the line numbers in the code example. If this selection is pasted into the macro editor, it won't work. All line numbers need to be removed, and the spaces adjusted so that the Python code has the proper indentation.



No text output from macros
Macros may output information to the report view to detail what the code is doing when it is running.

If no information is displayed, make sure the report view and Python console are visible, and that the output is directed tot he report view.

Printing information
FreeCAD macros have two methods to print information to the report view.

The FreeCAD functions

The simple Python function

Enabling the report view
To see the information displayed in the console you should:

1. Go to the menu.





2. Enable the and the.



3. The panels are now visible, and commands like now print information that appears in the.



Enabling the print command
FreeCAD may need to be configured so the function of Python redirects its output correctly to the report view.

1. Go into the Preferences Editor with the menu.



2. Go to section, and then.



3. Check both boxes:


 * [[Image:Case_a_cocher_O.png|16px]] Redirect internal Python output to report view


 * [[Image:Case_a_cocher_O.png|16px]] Redirect internal Python errors to report view

and then press the button.