Makrodefinicje

From FreeCAD Documentation
Revision as of 16:45, 9 September 2010 by Kwahoo (talk | contribs) (Created page with 'Makra są wygodnym sposobem na tworzenie skomplikowanych działań we FreeCADzie. Po prostu nagrywasz działania kiedy wykonujesz, następnie zapisujesz pod jakąś nazwą i odtw…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Makra są wygodnym sposobem na tworzenie skomplikowanych działań we FreeCADzie. Po prostu nagrywasz działania kiedy wykonujesz, następnie zapisujesz pod jakąś nazwą i odtwarzasz kiedy chcesz. Ponieważ makra są w rzeczywsistośco listą poleceń pythona, możesz je edytować i tworzyć bardzo skomplikowane skrypty.

Jak to działa

Jeśli aktywujesz wyjście konsoli (Menu Edit -> Preferences -> General -> Macros -> Show scripts commands in python console), zobaczysz je we FreeCADzie. Każdą akcja jaką wykonasz, jak naciśnięcie przycisku, wyzwoli polecenie pythona. Te polecenia są tym co może być zapisane w makrze. Główne narzędzie do tworzenia makr w pasku narzędzi makr: . Masz na nim cztery przyciski: Nagrywaj, zatrzymaj nagrywanie, zatrzymaj o odtwarzaj aktualne makro.

Użytkowanie jest bardzo proste: naciśnij przycisk nagrywania, zostaniesz zapytany o nazwę dla makra, następnie wykonaj kilka działań. Kiedy skończysz. kliknij przycisk zatrzymujący nagrywanie, twoje działania zostaną zapisane. Teraz możesz uzyskać dostęp do okna dialogowego makra dzięki przyciskowi edycji:

W tym miejscu możesz zarządzać makrami, usuwać je lub tworzyć nowe od podstaw. Przy edycji makra zostanie ono otwarte w oknie edytora, gdzie możesz dokonywać zmian w kodzie makra.

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/pl
Introduction to python/pl
Available translations of this page: Template:Se