How to install macros: Difference between revisions

From FreeCAD Documentation
(translate)
(Marked this version for translation)
Line 1: Line 1:
{{VeryImportantMessage|'''This tutorial has been translated with [https://translate.google.com/ Google translate] a rereading correction will be appreciated, thank you after confirmation to remove this banner'''}}
{{VeryImportantMessage|'''This tutorial has been translated with [https://translate.google.com/ Google translate] a rereading correction will be appreciated, thank you after confirmation to remove this banner'''}}
<translate>
<translate>
<!--T:1-->
{{TutorialInfo|Class=Programming|Level=Medium programmer|Time=15 minutes|FCVersion=All|Author=[[User:Mario52|Mario52]]|FCVersion=All}}
{{TutorialInfo|Class=Programming|Level=Medium programmer|Time=15 minutes|FCVersion=All|Author=[[User:Mario52|Mario52]]|FCVersion=All}}


==Description==
==Description== <!--T:2-->
This short tutorial will guide you on how to use macros available and incorporate them into the FreeCAD editor.
This short tutorial will guide you on how to use macros available and incorporate them into the FreeCAD editor.


<!--T:3-->
This tutorial was made on the Windows platform a small adjustment path may be necessary for other systems.
This tutorial was made on the Windows platform a small adjustment path may be necessary for other systems.


==Python==
==Python== <!--T:4-->
Python is a programming language, very simple to use and very fast to [[Introduction_to_Python|learn]].
Python is a programming language, very simple to use and very fast to [[Introduction_to_Python|learn]].


<!--T:5-->
Extending Python files is '''.py'''. FreeCAD macros have the extension '''.FCMacro''' but can also be executed with the extension '''.py'''. Python was invented to [https://www.python.org/~guido/ Guido Van Rossun]
Extending Python files is '''.py'''. FreeCAD macros have the extension '''.FCMacro''' but can also be executed with the extension '''.py'''. Python was invented to [https://www.python.org/~guido/ Guido Van Rossun]


==The Macro Menu and Toolbar Icons==
==The Macro Menu and Toolbar Icons== <!--T:6-->


<!--T:7-->
[[Image:Macro-record.svg|32px|record]] [[Std_DlgMacroRecord|Launch Record]]
[[Image:Macro-record.svg|32px|record]] [[Std_DlgMacroRecord|Launch Record]]
[[Image:Macro-stop.svg|32px|stop]] [[Std_DebugStop|Stop Record]]
[[Image:Macro-stop.svg|32px|stop]] [[Std_DebugStop|Stop Record]]
Line 22: Line 26:
[[Image:Debug-stop.svg|32px|stop]] [[Std_DlgMacroStop|Stop]]
[[Image:Debug-stop.svg|32px|stop]] [[Std_DlgMacroStop|Stop]]


==Location and destination macros==
==Location and destination macros== <!--T:8-->


<!--T:9-->
This section allows you to locate the final location of your macros.
This section allows you to locate the final location of your macros.


<!--T:10-->
'''1 :''' click '''Menu > Macro > Macros''' or the click the bottom [[File:Std DlgMacroExecuteDirect.svg|24px]] "Open a dialog to let you execute a macro Recorded"
'''1 :''' click '''Menu > Macro > Macros''' or the click the bottom [[File:Std DlgMacroExecuteDirect.svg|24px]] "Open a dialog to let you execute a macro Recorded"


<!--T:11-->
[[File:Dxf_Importer_Install_01.png|640px|center]]
[[File:Dxf_Importer_Install_01.png|640px|center]]


<!--T:12-->
'''2 :''' one dialog box open
'''2 :''' one dialog box open


<!--T:13-->
'''3 :''' the address of "Macro destination" (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''')
'''3 :''' the address of "Macro destination" (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''')


<!--T:14-->
In Ubuntu, this is normally '''/home/your_user_name/.FreeCAD'''
In Ubuntu, this is normally '''/home/your_user_name/.FreeCAD'''


<!--T:15-->
'''4 :''' copy the address of "Macro destination" (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''')
'''4 :''' copy the address of "Macro destination" (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''')


<!--T:16-->
[[File:Dxf_Importer_Install_02.png|640px|center]]
[[File:Dxf_Importer_Install_02.png|640px|center]]


<!--T:17-->
'''5 :''' paste the address into your browser and confirm
'''5 :''' paste the address into your browser and confirm


<!--T:18-->
[[File:Dxf_Importer_Install_03.png|640px|center]]
[[File:Dxf_Importer_Install_03.png|640px|center]]


<!--T:19-->
'''6 :''' leave open the explorer
'''6 :''' leave open the explorer


<!--T:20-->
[[File:Dxf_Importer_Install_04.png|640px|center]]
[[File:Dxf_Importer_Install_04.png|640px|center]]
{{clear}}
{{clear}}




<!--T:21-->
'''Section to read if you are not familiar with Python programming (common mistakes copy/paste).'''
'''Section to read if you are not familiar with Python programming (common mistakes copy/paste).'''


<div class="toccolours mw-collapsible mw-collapsed">
<div class="toccolours mw-collapsible mw-collapsed">
==The indentation errors examples wrong code==
==The indentation errors examples wrong code== <!--T:22-->
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">


<!--T:23-->
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 :
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 :


<!--T:24-->
<span style="color:red">
<span style="color:red">
'''<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'))'''
'''<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'))'''
</span>
</span>


<!--T:25-->
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.
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.


<!--T:26-->
'''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.
'''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.


<!--T:27-->
[[Image:Macro Install HowTo 09.png|center|the code was stuck without any indentation]]
[[Image:Macro Install HowTo 09.png|center|the code was stuck without any indentation]]


<!--T:28-->
'''2 :''' the code was correct indentations in the right place.
'''2 :''' the code was correct indentations in the right place.


<!--T:29-->
[[Image:Macro Install HowTo 10.png|center|the code was correct indentations in the right place]]
[[Image:Macro Install HowTo 10.png|center|the code was correct indentations in the right place]]


<!--T:30-->
'''3 :''' we select the code, and we see that the selection is at the edge of the code, the macro must works so good
'''3 :''' we select the code, and we see that the selection is at the edge of the code, the macro must works so good


<!--T:31-->
[[Image:Macro Install HowTo 11.png|center|the macro must works so good]]
[[Image:Macro Install HowTo 11.png|center|the macro must works so good]]


<!--T:32-->
'''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'''
'''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'''


<!--T:33-->
[[Image:Macro Install HowTo 12.png|center|remove one space all lines]]
[[Image:Macro Install HowTo 12.png|center|remove one space all lines]]


<!--T:34-->
'''5 :''' Here the code has been copied in a forum window with the {{KEY|Select all}} button apparently the selection is good
'''5 :''' Here the code has been copied in a forum window with the {{KEY|Select all}} button apparently the selection is good


<!--T:35-->
[[Image:Macro Install HowTo 14.png|center|640px|Here the code has been copied in a forum]]
[[Image:Macro Install HowTo 14.png|center|640px|Here the code has been copied in a forum]]


<!--T:36-->
'''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
'''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


<!--T:37-->
[[Image:Macro Install HowTo 15.png|center|640px|But the selection pasted into the FreeCAD editor gives a surprise]]
[[Image:Macro Install HowTo 15.png|center|640px|But the selection pasted into the FreeCAD editor gives a surprise]]


<!--T:38-->
'''7 :''' You must delete all the extra space that is four spaces on each line (for Windows word processing [http://notepad-plus-plus.org/ notepad-plus-plus] enables vertical selection with a combination of buttons {{KEY|Alt}} + Mouse dragging or Menu> Edit> Indent> Decrease the indentation
'''7 :''' You must delete all the extra space that is four spaces on each line (for Windows word processing [http://notepad-plus-plus.org/ notepad-plus-plus] enables vertical selection with a combination of buttons {{KEY|Alt}} + Mouse dragging or Menu> Edit> Indent> Decrease the indentation


<!--T:39-->
[[Image:Macro Install HowTo 16.png|center|640px|You must delete all the extra space]]
[[Image:Macro Install HowTo 16.png|center|640px|You must delete all the extra space]]


<!--T:40-->
'''8 :''' Here the selection also take the column numbers which will also give an error
'''8 :''' Here the selection also take the column numbers which will also give an error


<!--T:41-->
[[Image:Macro_Install_HowTo_29.png|center|640px|Here the selection also take the column numbers]]
[[Image:Macro_Install_HowTo_29.png|center|640px|Here the selection also take the column numbers]]


<!--T:42-->
'''9 :''' Perfect code.
'''9 :''' Perfect code.


<!--T:43-->
[[Image:Macro Install HowTo 13.png|center|Perfect code]]
[[Image:Macro Install HowTo 13.png|center|Perfect code]]


<!--T:44-->
<br>
<br>
</div>
</div>
</div>
</div>


<!--T:45-->
'''Method 1:'''
'''Method 1:'''


<div class="toccolours mw-collapsible mw-collapsed">
<div class="toccolours mw-collapsible mw-collapsed">
==Method copy the code in one window and paste in the FreeCAD editor==
==Method copy the code in one window and paste in the FreeCAD editor== <!--T:46-->
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">


<!--T:47-->
For example we will copy the macro [[File:Part_Prism_Apothem.svg|16px]] [[Macro_Apothem_Based_Prism_GUI|Macro_Apothem_Based_Prism_GUI]]
For example we will copy the macro [[File:Part_Prism_Apothem.svg|16px]] [[Macro_Apothem_Based_Prism_GUI|Macro_Apothem_Based_Prism_GUI]]


<!--T:48-->
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 [[Customize_ToolsBar|toolsbar.]]
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 [[Customize_ToolsBar|toolsbar.]]


<!--T:49-->
[[File:Macro Install HowTo 28.png|300px|center|Download icon]]
[[File:Macro Install HowTo 28.png|300px|center|Download icon]]


<!--T:50-->
After copying your code we will paste the code in FreeCAD editor.
After copying your code we will paste the code in FreeCAD editor.


<!--T:51-->
'''1 :''' Open FreeCAD and open the editor in FreeCAD
'''1 :''' Open FreeCAD and open the editor in FreeCAD


<!--T:52-->
[[File:Dxf_Importer_Install_01.png|640px|center]]
[[File:Dxf_Importer_Install_01.png|640px|center]]


<!--T:53-->
'''2 :''' The window macros file opens, click {{KEY|Create}} button
'''2 :''' The window macros file opens, click {{KEY|Create}} button


<!--T:54-->
[[File:Macro Install HowTo 17.png|300px|center|The window macros file opens]]
[[File:Macro Install HowTo 17.png|300px|center|The window macros file opens]]


<!--T:55-->
'''3 :''' A new window opens, enter the macro name (here "'''Macro_Apothem_Based_Prism_GUI'''")and click the create {{KEY|Ok}} button
'''3 :''' A new window opens, enter the macro name (here "'''Macro_Apothem_Based_Prism_GUI'''")and click the create {{KEY|Ok}} button


<!--T:56-->
[[File:Macro Install HowTo 18.png|300px|center|enter the macro name]]
[[File:Macro Install HowTo 18.png|300px|center|enter the macro name]]


<!--T:57-->
'''4 :''' The editing window FreeCAD macros is now available and has the name of our future macro.
'''4 :''' The editing window FreeCAD macros is now available and has the name of our future macro.


<!--T:58-->
[[File:Macro Install HowTo 19.png|640px|center|The editing window FreeCAD macros]]
[[File:Macro Install HowTo 19.png|640px|center|The editing window FreeCAD macros]]


<!--T:59-->
'''5 :''' Paste your code in the macro editor window and click the little '''cross''' to close the window.
'''5 :''' Paste your code in the macro editor window and click the little '''cross''' to close the window.


<!--T:60-->
[[File:Macro Install HowTo 20.png|640px|center|close the window]]
[[File:Macro Install HowTo 20.png|640px|center|close the window]]


<!--T:61-->
'''6 :''' A warning window appears asking for confirmation of save code, click on {{KEY|Yes}}
'''6 :''' A warning window appears asking for confirmation of save code, click on {{KEY|Yes}}


<!--T:62-->
'''PS:''' For the change silk consideration must save the macro and reopen it and just run it.
'''PS:''' For the change silk consideration must save the macro and reopen it and just run it.


<!--T:63-->
[[File:Macro Install HowTo 27.png|300px|center|A warning window appears asking for confirmation of save code]]
[[File:Macro Install HowTo 27.png|300px|center|A warning window appears asking for confirmation of save code]]


<!--T:64-->
'''7 :''' Repeat the number '''1 :''' , Click on your new macro and button {{KEY|Execute}}
'''7 :''' Repeat the number '''1 :''' , Click on your new macro and button {{KEY|Execute}}


<!--T:65-->
[[File:Macro Install HowTo 21.png|300px|center|Click on your new macro and button Execute]]
[[File:Macro Install HowTo 21.png|300px|center|Click on your new macro and button Execute]]


<!--T:66-->
'''8 :''' The macro runs, complete the fields with your values and click the {{KEY|OK}} button
'''8 :''' The macro runs, complete the fields with your values and click the {{KEY|OK}} button


<!--T:67-->
[[File:Macro Install HowTo 22.png|640px|center|The macro runs, complete the fields]]
[[File:Macro Install HowTo 22.png|640px|center|The macro runs, complete the fields]]


<!--T:68-->
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.
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.


<!--T:69-->
[[File:Macro Install HowTo 23.png|640px|center|The macro returns an error!]]
[[File:Macro Install HowTo 23.png|640px|center|The macro returns an error!]]


<!--T:70-->
10 : Here is your prism
10 : Here is your prism


<!--T:71-->
[[File:Macro Install HowTo 24.png|640px|center|your prism]]
[[File:Macro Install HowTo 24.png|640px|center|your prism]]


<!--T:72-->
11 : You can also open your macro in the editor to run or modify, click the {{KEY|Edit}} button
11 : You can also open your macro in the editor to run or modify, click the {{KEY|Edit}} button


<!--T:73-->
[[File:Macro Install HowTo 25.png|300px|center|You can also open your macro in the editor]]
[[File:Macro Install HowTo 25.png|300px|center|You can also open your macro in the editor]]


<!--T:74-->
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|16px]] green in the macros toolsbar
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|16px]] green in the macros toolsbar


<!--T:75-->
[[File:Macro Install HowTo 26.png|640px|center|The macro is now in the FreeCAD editor]]
[[File:Macro Install HowTo 26.png|640px|center|The macro is now in the FreeCAD editor]]


<!--T:76-->
</div>
</div>
</div>
</div>


<!--T:77-->
'''Method 2:'''
'''Method 2:'''


<div class="toccolours mw-collapsible mw-collapsed">
<div class="toccolours mw-collapsible mw-collapsed">
==Method macro in a compressed .ZIP file==
==Method macro in a compressed .ZIP file== <!--T:78-->
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">


<!--T:79-->
Download the file compressed here (example) [http://forum.freecadweb.org/viewtopic.php?f=22&t=6558#p52887 Macro_screw_maker 1.7]. (the page [[Macro_screw_maker1_2|Macro_screw_maker]])
Download the file compressed here (example) [http://forum.freecadweb.org/viewtopic.php?f=22&t=6558#p52887 Macro_screw_maker 1.7]. (the page [[Macro_screw_maker1_2|Macro_screw_maker]])


<!--T:80-->
Free for Windows [http://www.7-zip.org/ 7-zip] ou [http://www.kanmandet.dk/?p=37 L-Zarc] ou [http://www.quickzip.org/quickzip51.html quickzip]
Free for Windows [http://www.7-zip.org/ 7-zip] ou [http://www.kanmandet.dk/?p=37 L-Zarc] ou [http://www.quickzip.org/quickzip51.html quickzip]


<!--T:81-->
For Linux use this on the terminal
For Linux use this on the terminal


<!--T:82-->
{{Code|code=
{{Code|code=
unzip your_file.zip -d your_directory
unzip your_file.zip -d your_directory
}}
}}


<!--T:83-->
you must unzip the zip and copy the file (or all the files and folders) in your macro directory.
you must unzip the zip and copy the file (or all the files and folders) in your macro directory.


<!--T:84-->
'''Process'''
'''Process'''


<!--T:85-->
'''1 :''' Download your file in your local folder here the folder '''Temp'''
'''1 :''' Download your file in your local folder here the folder '''Temp'''


<!--T:86-->
[[Image:Macro Install HowTo 01.png|center|640px|Download your file in your local folder here the folder Temp]]
[[Image:Macro Install HowTo 01.png|center|640px|Download your file in your local folder here the folder Temp]]


<!--T:87-->
'''2 :''' Unzip your file in the folder.
'''2 :''' Unzip your file in the folder.


<!--T:88-->
[[Image:Macro Install HowTo 02.png|center|640px|Unzip your file in the folder.
[[Image:Macro Install HowTo 02.png|center|640px|Unzip your file in the folder.
]]
]]


<!--T:89-->
'''3 :''' The decompressor finished his work and created a new folder with the unpacked file
'''3 :''' The decompressor finished his work and created a new folder with the unpacked file


<!--T:90-->
[[Image:Macro Install HowTo 03.png|center|640px|The decompressor finished his work and created a new folder with the unpacked file]]
[[Image:Macro Install HowTo 03.png|center|640px|The decompressor finished his work and created a new folder with the unpacked file]]


<!--T:91-->
'''4 :''' Enter in the newly created directory, move about the file, click the right mouse button and click on '''Cut'''.
'''4 :''' Enter in the newly created directory, move about the file, click the right mouse button and click on '''Cut'''.


<!--T:92-->
[[Image:Macro Install HowTo 04.png|center|640px|Enter in the newly created directory]]
[[Image:Macro Install HowTo 04.png|center|640px|Enter in the newly created directory]]


<!--T:93-->
'''5 :''' Return to your browser remained open in the macro location (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''') and close the browser.
'''5 :''' Return to your browser remained open in the macro location (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''') and close the browser.


<!--T:94-->
[[Image:Macro Install HowTo 05.png|center|640px|Return to your browser remained open]]
[[Image:Macro Install HowTo 05.png|center|640px|Return to your browser remained open]]


<!--T:95-->
'''6 :''' Open FreeCAD click '''Menu > Macro > Macros''' or the click the {{KEY|bottom}} [[File:Std_DlgMacroExecuteDirect.svg|18px]] "Open a dialog to let you execute a macro Recorded"
'''6 :''' Open FreeCAD click '''Menu > Macro > Macros''' or the click the {{KEY|bottom}} [[File:Std_DlgMacroExecuteDirect.svg|18px]] "Open a dialog to let you execute a macro Recorded"


<!--T:96-->
[[Image:Macro Install HowTo 06.png|center|640px|Open FreeCAD]]
[[Image:Macro Install HowTo 06.png|center|640px|Open FreeCAD]]


<!--T:97-->
'''7 :''' The macros window open , select your macro and click the button {{KEY|Execute}}
'''7 :''' The macros window open , select your macro and click the button {{KEY|Execute}}


<!--T:98-->
[[Image:Macro Install HowTo 07.png|center|640px|The macros window open]]
[[Image:Macro Install HowTo 07.png|center|640px|The macros window open]]


<!--T:99-->
'''8 :''' Your macro is executed enter the data and click the {{KEY|Create}} button
'''8 :''' Your macro is executed enter the data and click the {{KEY|Create}} button


<!--T:100-->
[[Image:Macro Install HowTo 08.png|center|640px|Your macro is executed]]
[[Image:Macro Install HowTo 08.png|center|640px|Your macro is executed]]


<!--T:101-->
'''9''' : Whaouu
'''9''' : Whaouu


<!--T:102-->
[[Image:Macro Install HowTo 30.png|center|640px|Whaouu]]
[[Image:Macro Install HowTo 30.png|center|640px|Whaouu]]


<!--T:103-->
</div>
</div>
</div>
</div>


<!--T:104-->
End tutorial good job.
End tutorial good job.


==Links==
==Links== <!--T:105-->


<!--T:106-->
The [[Macros_recipes|Macros_recipes]] page
The [[Macros_recipes|Macros_recipes]] page



Revision as of 16:23, 29 December 2014

This tutorial has been translated with Google translate a rereading correction will be appreciated, thank you after confirmation to remove this banner
Tutorial
Topic
{{{Topic}}}
Level
Medium programmer
Time to complete
15 minutes
Authors
Mario52
FreeCAD version
All
Example files
None
See also
None

Description

This short tutorial will guide you on how to use macros available and incorporate them into the FreeCAD editor.

This tutorial was made on the Windows platform a small adjustment path may be necessary for other systems.

Python

Python is a programming language, very simple to use and very fast to learn.

Extending Python files is .py. FreeCAD macros have the extension .FCMacro but can also be executed with the extension .py. Python was invented to Guido Van Rossun

The Macro Menu and Toolbar Icons

record Launch Record stop Stop Record open editor Open Menu macro execute Execute start Debug Macro stop Stop

Location and destination macros

This section allows you to locate the final location of your macros.

1 : click Menu > Macro > Macros or the click the bottom "Open a dialog to let you execute a macro Recorded"

2 : one dialog box open

3 : the address of "Macro destination" (here C:\Users\your_user_name\AppData\Roaming\FreeCAD\)

In Ubuntu, this is normally /home/your_user_name/.FreeCAD

4 : copy the address of "Macro destination" (here C:\Users\your_user_name\AppData\Roaming\FreeCAD\)

5 : paste the address into your browser and confirm

6 : leave open the explorer


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.

the code was stuck without any indentation
the code was stuck without any indentation

2 : the code was correct indentations in the right place.

the code was correct indentations in the right place
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

the macro must works so good
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

remove one space all lines
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

Here the code has been copied in a forum
Here the code has been copied in a forum

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

But the selection pasted into the FreeCAD editor gives a surprise
But the selection pasted into the FreeCAD editor gives a surprise

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

You must delete all the extra space
You must delete all the extra space

8 : Here the selection also take the column numbers which will also give an error

Here the selection also take the column numbers
Here the selection also take the column numbers

9 : Perfect code.

Perfect code
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.

Download icon
Download icon

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

The window macros file opens
The window macros file opens

3 : A new window opens, enter the macro name (here "Macro_Apothem_Based_Prism_GUI")and click the create Ok button

enter the macro name
enter the macro name

4 : The editing window FreeCAD macros is now available and has the name of our future macro.

The editing window FreeCAD macros
The editing window FreeCAD macros

5 : Paste your code in the macro editor window and click the little cross to close the window.

close the window
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.

A warning window appears asking for confirmation of save code
A warning window appears asking for confirmation of save code

7 : Repeat the number 1 : , Click on your new macro and button Execute

Click on your new macro and button Execute
Click on your new macro and button Execute

8 : The macro runs, complete the fields with your values and click the OK button

The macro runs, complete the fields
The macro runs, complete the fields

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.

The macro returns an error!
The macro returns an error!

10 : Here is your prism

your prism
your prism

11 : You can also open your macro in the editor to run or modify, click the Edit button

You can also open your macro in the editor
You can also open your macro in the editor

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

The macro is now in the FreeCAD editor
The macro is now in the FreeCAD editor

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

Download your file in your local folder here the folder Temp
Download your file in your local folder here the folder Temp

2 : Unzip your file in the folder.

Unzip your file in the folder.
Unzip your file in the folder.

3 : The decompressor finished his work and created a new folder with the unpacked file

The decompressor finished his work and created a new folder with the unpacked file
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.

Enter in the newly created directory
Enter in the newly created directory

5 : Return to your browser remained open in the macro location (here C:\Users\your_user_name\AppData\Roaming\FreeCAD\) and close the browser.

Return to your browser remained open
Return to your browser remained open

6 : Open FreeCAD click Menu > Macro > Macros or the click the bottom "Open a dialog to let you execute a macro Recorded"

Open FreeCAD
Open FreeCAD

7 : The macros window open , select your macro and click the button Execute

The macros window open
The macros window open

8 : Your macro is executed enter the data and click the Create button

Your macro is executed
Your macro is executed

9 : Whaouu

Whaouu
Whaouu

End tutorial good job.

Links

The Macros_recipes page