Macros/sv: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
Line 1: Line 1:
Makron är ett smidigt sätt att skapa komplexa aktioner i FreeCAD. Du behöver bara spela in aktioner samtidigt som du gör dem, och sedan spara det under ett namn, och senare spela upp det när du vill. Eftersom makron i realiteten är en lista av python kommandon, så kan du även redigera det, och skapa mycket komplexa skript.
Macros are a convenient way to create complex actions in FreeCAD. You simply record actions as you do them, then save that 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.



===Hur det fungerar===

Om du aktiverar konsolutmatning(Meny Redigera -> Alternativ -> Allmänt -> Makro -> Visa skriptkommandon i python konsolen), så kommer du se att varje aktion du gör i FreeCAD, , som att klicka på en knapp, genererar ett python kommando. Dessa kommandon är vad som kan spelas in i ett makro. Huvudverktyget för att göra makron är makroverktygslådan: [[Image:Macros_toolbar.jpg]]. På den finns det 4 knappar: Spela in, stoppa inspelning, redigera och spela upp det nuvarande makrot.



Det är mycket enkelt att använda: Klicka på inspelningsknappen, du kommer att efterfrågas om ett namn till ditt makro, utför sedan några aktioner. När du är klar, Klick på stoppa inspelning knappen, och dina aktioner kommer att spaaras. Du kan nu komma åt makrodialogen med redigeraknappen:


===How it works===
If you enable console output (Menu Edit -> Preferences -> General -> Macros -> Show scripts commands in python console), you will see that in FreeCAD, every action you do, such as pressing a button, outputs a python command. Thos commands are what can be recorded in a macro. The main tool for making macros is the macros toolbar: [[Image:Macros_toolbar.jpg]]. 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:


[[Image:Macros.jpg]]
[[Image:Macros.jpg]]


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===
Där kan du hantera dina makron, radera, redigera eller skapa nya från scratch. Om du redigerar ett makro, så kommer det att öppnas i ett redigeringsfönster där du kan förändra dess kod.
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:



===Exempel===

Klicka på inspelningsknappen, ge den ett namn, låt oss säga "cylinder 10x10", skapa skapa sedan med [[Part_Module/sv|Del arbetsbänken]] en cylinder med radien= 10 och höjden = 10. Klicka sedan på "stoppa inspelning" knappen. I redigera makro dialogen, så kan du se den python kod som har spelats in, och om du vill, göra ändringar på den. För att köra ditt makro, klicka på uppspelningsknappen i verktygslåden medan ditt makro är i redigeraren. Ditt makro sparas alltid till disk, så alla ändringar du gör, eller alla nya makron du skapar, kommer alltid att finnas tillgängliga nästa gång som du startar FreeCAD.

===Anpassning===

Det är förstås inte så praktiskt att behöva ladda ett makro i redigeraren för att kunna använda det. FreeCAD erbjuder många bättre sätt att använda ditt makro, som att tilldela en tangentbordsgenväg till den eller lägga till en punkt i menyn. När ditt makro är sparat, så kan allt detta göras via Verktyg -> Anpassa menyn:




[[Image:Macros config.jpg]]
[[Image:Macros config.jpg]]


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===
Pä detta sätt så kan du göra ditt makro till ett riktigt verktyg, precis som ett standardverktyg i FreeCAD . Detta, i tilläg till kraften hos pythonskripten i FreeCAD, gör det möjligt att lätt lägga till dina egna verktyg till gränssnittet. Läs vidare på [[Scripting/sv|Skript]] sidan om du vill veta mer om python skript...
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.


===Skapa makron utan inspelning===

Du kan också direkt kopiera/klistra in python kod till ett makro, utan att behöva spela in aktioner i gränssnittet. Skapa bara ett nytt makro, redigera det, och klistra in din kod. Ditt makro sparas automatiskt när du stänger makroredigerings fönstret.

===Makroförråd===

Besök [[Macros recipes/sv|Makrorecept]] sidan för att hämta några användbara makron att lägga till din FreeCAD installation.



===Macros repository===
{{docnav/sv|Image Module/sv|Introduction to python/sv}}
Visit the [[Macros recipes]] page to pick some useful macros to add to your FreeCAD installation.


{{docnav|Image Module|Introduction to python}}
{{languages/sv | {{en|Macros}} {{de|Macros/de}} {{es|Macros/es}} {{fr|Macros/fr}} {{it|Macros/it}} {{pl|Macros/pl}} {{ru|Macros/ru}} }}
[[Category:Poweruser Documentation]]


{{clear}}
[[Category:Poweruser Documentation/sv]]
<languages/>

Revision as of 21:41, 18 February 2014

Macros are a convenient way to create complex actions in FreeCAD. You simply record actions as you do them, then save that 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.

How it works

If you enable console output (Menu Edit -> Preferences -> General -> Macros -> Show scripts commands in python console), you will see that in FreeCAD, every action you do, such as pressing a button, outputs a python command. Thos 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:

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