Makra

From FreeCAD Documentation
Revision as of 10:18, 5 March 2014 by Honza32 (talk | contribs) (Created page with "===Jak to funguje=== Když povolíte výstup na konzolu (Menu Úpravy -> Předvolby -> Obecné -> Makra -> Zobraz skriptovací příkazy v konzole Pythonu), uvidíte ve FreeCA...")

Makra jsou pohodlný způsob jak provádět komplexní akce ve FreeCADu. Můžete jednoduše zaznamenat operace tak jak jste je prováděli, potom je uložit pod nějakým jménem a kdykoliv později je znovu spouštět. Vzhledem k tomu, že makra jsou ve skutečnosti jen seznamy příkazů Pythonu, můžete je upravovat a vytvářet velmi komplexní skripty.

Jak to funguje

Když povolíte výstup na konzolu (Menu Úpravy -> Předvolby -> Obecné -> Makra -> Zobraz skriptovací příkazy v konzole Pythonu), uvidíte ve FreeCADu, že každá operace, kterou provedete, jako je stisk tlačítka, zobrazí na výstupu příslušný příkaz Pythonu. Tyto příkazy jsou to, co se ukládá v makru. Hlavní nástroj pro vytváření maker je pruh nástrojů maker: . Na něm jsou 4 tlačítka: Spustit záznam, Zastavit záznam, Upravit makro a Spustit aktuální makro.

It is very simple to use: Press the record button, you will be asked to give a name to your macro, then perform some actions. When you are done, click the stop recording button, and your actions will be saved. You can now access the macro dialog with the edit button:

There you can manage your macros, delete, edit or create new ones from scratch. If you edit a macro, it will be opened in an editor window where you can make changes to its code.

Example

Press the record button, give a name, let's say "cylinder 10x10", then, in the Part Workbench, create a cylinder with radius = 10 and height = 10. Then, press the "stop recording" button. In the edit macros dialog, you can see the python code that has been recorded, and, if you want, make alterations to it. To execute your macro, simply press the execute button on the toolbar while your macro is in the editor. You macro is always saved to disk, so any change you make, or any new macro you create, will always be available next time you start FreeCAD.

Customizing

Of course it is not practical to load a macro in the editor in order to use it. FreeCAD provides much better ways to use your macro, such as assigning a keyboard shortcut to it or putting an entry in the menu. Once your macro is created, all this can be done via the Tools -> Customize menu:

This way you can make your macro become a real tool, just like any standard FreeCAD tool. This, added to the power of python scripting within FreeCAD, makes it possible to easily add your own tools to the interface. Read on to the Scripting page if you want to know more about python scripting...

Creating macros without recording

You can also directly copy/paste python code into a macro, without recording GUI action. Simply create a new macro, edit it, and paste your code. You can then save your macro the same way as you save a FreeCAD document. Next time you start FreeCAD, the macro will appear under the "Installed Macros" item of the Macro menu.

Macros repository

Visit the Macros recipes page to pick some useful macros to add to your FreeCAD installation.

Image Module
Introduction to python