How to install macros/pl

Opis
Od wersji v0.17 można łatwo dodać makrodefinicje za pomocą Menadżera dodatków. Użytkownik nie musi robić nic więcej niż używać tego narzędzia. Czytaj dalej, aby uzyskać więcej informacji na temat instalacji makrodefinicji.

Makrodefinicje to sekwencje poleceń, które służą do wykonania złożonej operacji rysunkowej. Makra są skryptami środowiska Python, co oznacza, że są to pliki tekstowe, które można pisać i edytować za pomocą edytora tekstu.

Podczas gdy skrypty Pythona zwykle mają rozszerzenie, makra FreeCAD powinny mieć rozszerzenie. Zbiór makr napisanych przez doświadczonych użytkowników znajduje się na stronie przepisy na makra.

Zobacz Wprowadzenie do Pythona, aby zapoznać się z językiem programowania Python, a następnie Poradnik do pisania skryptów Python i Podstawy skryptów FreeCAD, które pomogą Ci nauczyć się pisania makr.

Tutaj jest filmik o instalowaniu makrodefinicji FreeCAD w Ubuntu.



Pasek narzędzi

 * [[Image:Std_DlgMacroRecord.svg|32px]] Macro recording...
 * [[Image:Std_MacroStopRecord.svg|32px]] Stop macro recording
 * [[Image:Std_DlgMacroExecute.svg|32px]] Macros...
 * [[Image:Std_DlgMacroExecuteDirect.svg|32px]] Execute macro

Menu
Besides the tools in the toolbar, the following functions are also available in the menu.
 * Attach to remote debugger
 * [[Image:Std_MacroStartDebug.svg|32px]] Debug macro
 * [[Image:Std_MacroStopDebug.svg|32px]] Stop debugging
 * Step over
 * Step into
 * Toggle breakpoint



Katalog z makrodefinicjami
Macros are created in a specific folder under the user's FreeCAD directory. This directory can be configured in the Execute macro dialog, or in the Preferences Editor, through the menu.

Downloaded macros should also be placed in this directory.



Katalog domyślny
Macros can be simply copied into

where is a top level directory searched by FreeCAD on startup.

The could be a system wide directory, in which case the macro is installed for all users.
 * On Linux it is usually
 * On Windows it is usually
 * On Mac OSX it is usually

The could be a particular user's directory.
 * On Linux it is usually  or.
 * On Windows it is usually
 * On Mac OSX it is usually



Konfiguracja katalogu użytkownika
1. Open the menu to open the Execute macro dialog.



2. Set the appropriate.
 * Linux: usually  or
 * Windows: usually
 * MacOS: usually



3. Navigate to that directory in your computer.
 * Linux: paste the address into your file manager, "Nautilus" or other. You may have to press + to make the hidden directory visible.
 * Windows: paste the address into your "File explorer" and confirm.
 * MacOS: locate the folder in the "Finder" or paste the address into a "File explorer"; remember the prefix in the "File explorer" for a file on disk.



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.





Instalacja makropoleceń


Metoda automatyczna
Poczynając od FreeCAD 0.17, użyj Menadżera dodatków w menu głównym aby zainstalować makrodefinicje, która została dołączone do repozytorium FreeCAD-macros.

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.



Metoda manualna 1. Skopiuj kod do edytora makrodefinicji
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.





Metoda manualna 2. Dodanie pliku zawierającego makroinstrukcje ze skompresowanego pliku .zip
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.







Wykonanie makrodefinicji w wierszu poleceń
Command line execute a macro (.FCMacro or .py)

on Windows

on Linux



Błędy w makrodefinicjach


Błędy wcięć
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:



Przykład 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.





Przykład 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.





Przykład 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.





Przykład 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.





Dobry kod


<span id="No_text_output_from_macros">

Brak wyjścia tekstu z makrodefinicji
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.

<span id="Printing_information">

Informacje dotyczące drukowania
FreeCAD macros have two methods to print information to the report view.

The FreeCAD functions

The simple Python function

<span id="Enabling_the_report_view">

Uaktywnienie widoku raportu
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.



<span id="Enabling_the_print_command">

Włączenie polecenia <tt>print</tt>
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.