Macros: Difference between revisions
No edit summary |
|||
(One intermediate revision by the same user not shown) | |||
Line 10: | Line 10: | ||
[[Macros|Macros]] are a convenient way to reproduce complex actions in LabRPS. You simply record actions as you do them, then save those actions under a name, and replay them whenever you want. Since macros are in reality a list of [[Python|Python]] commands, you can also edit them, and create very complex scripts. | [[Macros|Macros]] are a convenient way to reproduce complex actions in LabRPS. You simply record actions as you do them, then save those actions under a name, and replay them whenever you want. Since macros are in reality a list of [[Python|Python]] commands, you can also edit them, and create very complex scripts. | ||
While Python scripts normally have the {{incode|.py}} extension, LabRPS macros should have the {{incode|. | While Python scripts normally have the {{incode|.py}} extension, LabRPS macros should have the {{incode|.RPSMacro}} extension. A collection of macros written by experienced users is found in the [[Macros_recipes|macros recipes]] page. | ||
See the [[Power_users_hub|Power users hub]] to learn more about the [[Python|Python]] programming language, and about writing macros. In particular, you should start with these pages: | See the [[Power_users_hub|Power users hub]] to learn more about the [[Python|Python]] programming language, and about writing macros. In particular, you should start with these pages: | ||
Line 30: | Line 30: | ||
== Example == | == Example == | ||
Press the record button, give a name, let's say " | Press the record button, give a name, let's say "wind on tall building", then, in the [[WindLab_Workbench|WindLab Workbench]], create a wind simulation. 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 LabRPS. | ||
== Customizing == | == Customizing == | ||
Line 39: | Line 39: | ||
This way you can make your macro become a real tool, just like any standard LabRPS tool. This, added to the power of python scripting within LabRPS, makes it possible to easily add your own tools to the interface. | This way you can make your macro become a real tool, just like any standard LabRPS tool. This, added to the power of python scripting within LabRPS, makes it possible to easily add your own tools to the interface. | ||
== Creating macros without recording == | == Creating macros without recording == | ||
Line 51: | Line 49: | ||
There are two main places for macros. The first one is the official peer-reviewed macro repository on [https://github.com/LabRPS/LabRPS-macros GitHub]. The second one is the [[Macros_recipes|Macros recipes]] page from which you can pick some useful macros to add to your LabRPS installation. Macros from both repositories can be installed via the [[Std_AddonMgr|Addon Manager]] directly from LabRPS. | There are two main places for macros. The first one is the official peer-reviewed macro repository on [https://github.com/LabRPS/LabRPS-macros GitHub]. The second one is the [[Macros_recipes|Macros recipes]] page from which you can pick some useful macros to add to your LabRPS installation. Macros from both repositories can be installed via the [[Std_AddonMgr|Addon Manager]] directly from LabRPS. | ||
== Tutorials == | == Tutorials == | ||
Line 61: | Line 54: | ||
You can manually install extensions, however, it is much simpler to just use the [[Std_AddonMgr|Addon Manager]]. | You can manually install extensions, however, it is much simpler to just use the [[Std_AddonMgr|Addon Manager]]. | ||
* [[How_to_install_macros|How to install macros]] | * [[How_to_install_macros|How to install macros]] | ||
Latest revision as of 19:24, 29 October 2024
Introduction
Macros are a convenient way to reproduce complex actions in LabRPS. You simply record actions as you do them, then save those actions under a name, and replay them whenever you want. Since macros are in reality a list of Python commands, you can also edit them, and create very complex scripts.
While Python scripts normally have the .py
extension, LabRPS macros should have the .RPSMacro
extension. A collection of macros written by experienced users is found in the macros recipes page.
See the Power users hub to learn more about the Python programming language, and about writing macros. In particular, you should start with these pages:
How it works
Enable the console output in the menu Edit → Preferences → Python → Macro → Show scripts commands in python console. You will see that in LabRPS, every action you do, such as pressing a button, outputs a Python command. Those commands are what can be recorded in a macro. The main tool for making macros is the macros toolbar: . On it you have 4 buttons: Record, stop recording, edit and play the current macro.
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.
Macro dialog, listing the macros available in the system
There you can manage your macros, delete, edit, duplicate, install 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. New macros can be installed using the Addons... button, which links to the Addon Manager.
Example
Press the record button, give a name, let's say "wind on tall building", then, in the WindLab Workbench, create a wind simulation. 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 LabRPS.
Customizing
Of course it is not practical to load a macro in the editor in order to use it. LabRPS 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 LabRPS tool. This, added to the power of python scripting within LabRPS, makes it possible to easily add your own tools to the interface.
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 LabRPS document. Next time you start LabRPS, the macro will appear under the "Installed Macros" item of the Macro menu.
See How to install macros for a more detailed description.
Macro repositories
There are two main places for macros. The first one is the official peer-reviewed macro repository on GitHub. The second one is the Macros recipes page from which you can pick some useful macros to add to your LabRPS installation. Macros from both repositories can be installed via the Addon Manager directly from LabRPS.
Tutorials
You can manually install extensions, however, it is much simpler to just use the Addon Manager.
- LabRPS scripting: Python, Introduction to Python, Python scripting tutorial, LabRPS Scripting Basics
- Modules: Units, Quantity
- Workbenches: Gui Commands, Commands
- Parametric objects: Scripted objects, Viewproviders
- Graphical interface: Interface creation, Interface creation completely in Python, PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Other: Expressions
- Hubs: User hub, Power users hub, Developer hub