Comment installer des macros
Tutoriel |
Thème |
---|
{{{Topic}}} |
Niveau |
Programmeur moyen |
Temps d'exécution estimé |
15 minutes |
Auteurs |
Mario52 |
Version de FreeCAD |
Toutes versions |
Fichiers exemples |
None |
Voir aussi |
None |
Description
Ce petit tutoriel vous guide sur la façon d'utiliser les macros disponibles et de les incorporer dans l'éditeur de FreeCAD.
Ce tutoriel a été fait sur la plateforme Windows une petite adaptation des chemins sera peut être nécessaire pour d'autres systèmes.
Python
Python est un langage de programmation vraiment simple d'utilisation et vraiment facile à apprendre. Python a été inventé par Guido Van Rossun
L'extension des fichiers Python est .py. Les macros de FreeCAD ont l'extension .FCMacro mais peuvent aussi être exécutées avec l'extension .py.
Les outils disponibles pour les macros
record Launch Record stop Stop Record Open Menu macro execute Execute Debug Macro Stop
Localisation et destination des macros
Cette section vous permet de localiser l'emplacement définitif de vos macros.
1: Cliquer Menu > Macro > Macros ou cliquez sur le bouton 24px "pour ouvrir une boîte de dialogue et vous permettre d'exécuter une macro enregistrée"
2 : une boîte de dialogue s'ouvre
3 : l'adresse de destination des Macros est (ici C:\Users\your_user_name\AppData\Roaming\FreeCAD\)
Sur Ubuntu, normalement ce serait /home/your_user_name/.FreeCAD
4 : copiez l'adresse de destination des Macros (ici C:\Users\your_user_name\AppData\Roaming\FreeCAD\)
5 : collez l'adresse dans la boîte de dialogue de votre explorateur et confirmez
6 : gardez votre explorateur ouvert
Section to read if you are not familiar with Python programming (common mistakes copy/paste).
The indentation errors examples wrong code
The indentation in the phyton programming is very important and integral part of the code, a space or an inappropriate shift causes an indentation error ex :
<unknown exception traceback><type 'exceptions.IndentationError'>: ('expected an indented block', ('C:/Users/d/AppData/Roaming/FreeCAD/Macro_Apothem_Based_Prism_GUI.FCMacro', 21, 3, 'def priSm(self):\n'))
gives the error returned 'expected an indented block' block indentation expected to line 21, 3, normal after a class p (): must be the next line an indentation at least one space.
1 : In this example, the code was stuck without any indentation and of course does not work! here definitely a programmer error when pasting the code on the page as it would have never known it to work.
2 : the code was correct indentations in the right place.
3 : we select the code, and we see that the selection is at the edge of the code, the macro must works so good
4 : Here additional space is selected (it can happen) then you need to copy the code into a word processor to remove one space all lines
5 : Here the code has been copied in a forum window with the Select all button apparently the selection is good
6 : But the selection pasted into the FreeCAD editor gives a surprise, an indent of four spaces has been added by the system ? the code is not good
7 : You must delete all the extra space that is four spaces on each line, for Windows word processing notepad-plus-plus enables vertical selection with a combination of buttons Alt + Mouse dragging or Menu> Edit> Indent> Decrease the indentation
8 : Here the selection also take the column numbers which will also give an error
9 : Perfect code.
Method 1:
Method copy the code in one window and paste in the FreeCAD editor
For example we will copy the macro Macro_Apothem_Based_Prism_GUI
If there are one or more icon (s) download also position your mouse over the icon, click the right mouse button and click "Save image as ..." the icon or icons are placed in the macro directory and one of these icons serve as a shortcut icon to place on the toolsbar.
After copying your code we will paste the code in FreeCAD editor.
1 : Open FreeCAD and open the editor in FreeCAD
2 : The window macros file opens, click Create button
3 : A new window opens, enter the macro name (here "Macro_Apothem_Based_Prism_GUI")and click the create Ok button
4 : The editing window FreeCAD macros is now available and has the name of our future macro.
5 : Paste your code in the macro editor window and click the little cross to close the window.
6 : A warning window appears asking for confirmation of save code, click on Yes
PS: For the change silk consideration must save the macro and reopen it and just run it.
7 : Repeat the number 1 : , Click on your new macro and button Execute
8 : The macro runs, complete the fields with your values and click the OK button
9 : The macro returns an error ! we do not have to open document, open a document and repeat the operation 7 and 8. Some macros open a new document if it does not find one.
10 : Here is your prism
11 : You can also open your macro in the editor to run or modify, click the Edit button
12: The macro is now in the FreeCAD editor you can run through the menu "Macro Run Macro" or by clicking on the triangle File:Macro-execute.svg green in the macros toolsbar
Method 2:
Method macro in a compressed .ZIP file
Download the file compressed here (example) Macro_screw_maker 1.7. (the page Macro_screw_maker)
Free for Windows 7-zip ou L-Zarc ou quickzip
For Linux use this on the terminal
unzip your_file.zip -d your_directory
you must unzip the zip and copy the file (or all the files and folders) in your macro directory.
Process
1 : Download your file in your local folder here the folder Temp
2 : Unzip your file in the folder.
3 : The decompressor finished his work and created a new folder with the unpacked file
4 : Enter in the newly created directory, move about the file, click the right mouse button and click on Cut.
5 : Return to your browser remained open in the macro location (here C:\Users\your_user_name\AppData\Roaming\FreeCAD\) and close the browser.
6 : Open FreeCAD click Menu > Macro > Macros or the click the bottom "Open a dialog to let you execute a macro Recorded"
7 : The macros window open , select your macro and click the button Execute
8 : Your macro is executed enter the data and click the Create button
9 : Whaouu
End tutorial good job.
Links
The Macros_recipes page