How to install macros/ro: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<div class="mw-translate-fuzzy">
{{TutorialInfo|Topic=Programming|Level=Medium programmer|Time=15 minutes|FCVersion=All|Author=[[User:Mario52|Mario52]]}}
{{TutorialInfo/ro|Topic=Programming|Level=Medium programmer|Time=15 minutes|FCVersion=All|Author=[[User:Mario52|Mario52]]}}
</div>


<div class="mw-translate-fuzzy">
==Descriere==
==Descriere==
Acest tutorial scurt vă va arăta cum să instalați și să utilizați macrocomenzile FreeCAD.
Acest tutorial scurt vă va arăta cum să instalați și să utilizați macrocomenzile FreeCAD.
</div>


Since v0.17 it is easy to add macros by using the [[Std_AddonMgr|Addon Manager]]. A regular user doesn't need to do more than use this tool. Keep reading for more information regarding installation of [[macros|macros]].
Acest tutorial a fost realizat pe platforma Windows, astfel încât o mică ajustare ar putea fi necesară pentru alte sisteme.
A fost actualizat pentru a acoperi platforma Macintosh.


Macros are sequences of commands which are used to perform a complex drawing operation. Macros are [[Python|Python]] scripts, which means they are text files that can be written and edited with a text editor.
==Python==
Python este un limbaj de programare care este foarte simplu de utilizat și se învață foarte rapid.[[Introduction_to_Python|learn]].


While Python scripts normally have the {{incode|.py}} extension, FreeCAD macros should have the {{incode|.FCMacro}} extension. A collection of macros written by experienced users is found in the [[macros recipes|macros recipes]] page.
Fișierele Python au o extensie de forma '''.py''' iar fișierele macrocomenzi FreeCAD (care sunt de asemenea fișiere Python ) ustilizează extensia '''.FCMacro'''. FreeCAD Macro facility pot de asemenea executa fișiere cu extensia '''.py'''. Python a fost inventat de către [https://www.python.org/~guido/ Guido Van Rossun]


See [[Introduction to Python|Introduction to Python]] to learn about the Python programming language, and then [[Python scripting tutorial|Python scripting tutorial]] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]] to learn about writing macros.

Here is a video on [https://wiki.opensourceecology.org/wiki/Installing_Macros_in_FreeCAD installing FreeCAD macros in Ubuntu].

<div class="mw-translate-fuzzy">
== Meniul Macro Menu și Iconițele Instrumentelor==
== Meniul Macro Menu și Iconițele Instrumentelor==
</div>


<div class="mw-translate-fuzzy">
[[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 21: Line 30:
[[Image:Debug-start.svg|32px|start]] [[Std_DebugMacro|Debug Macro]]
[[Image:Debug-start.svg|32px|start]] [[Std_DebugMacro|Debug Macro]]
[[Image:Debug-stop.svg|32px|stop]] [[Std_DlgMacroStop|Stop]]
[[Image:Debug-stop.svg|32px|stop]] [[Std_DlgMacroStop|Stop]]
</div>


===Menu===
Besides the tools in the toolbar, the following functions are also available in the {{MenuCommand|Macro}} menu.
* [[Std_MacroAttachDebugger|Attach to remote debugger]]
* [[Image:Std_MacroStartDebug.svg|32px]] [[Std_MacroStartDebug|Debug macro]]
* [[Image:Std_MacroStopDebug.svg|32px]] [[Std_MacroStopDebug|Stop debugging]]
* [[Std_MacroStepOver|Step over]]
* [[Std_MacroStepInto|Step into]]
* [[Std_ToggleBreakpoint|Toggle breakpoint]]

<div class="mw-translate-fuzzy">
==Locația și destinația mcrocomanzilor==
==Locația și destinația mcrocomanzilor==
</div>

<div class="toccolours mw-collapsible mw-collapsed">

Macros are created in a specific folder under the user's FreeCAD directory. This directory can be configured in the [[Std_DlgMacroExecute|Execute macro dialog]], or in the [[Preferences Editor|Preferences Editor]], through the menu {{MenuCommand|Edit → Preferences → General → Macro → Macro recording settings}}.

Downloaded macros should also be placed in this directory.

<div class="mw-collapsible-content">

=== Default directory ===
Macros can be simply copied into

{{Code|code=
$ROOT_DIR/
}}

where {{incode|$ROOT_DIR}} is a top level directory searched by FreeCAD on startup.

The {{incode|$ROOT_DIR}} could be a system wide directory, in which case the macro is installed for all users.
* On Linux it is usually {{incode|/usr/share/freecad/}}
* On Windows it is usually {{incode|C:\Program Files\FreeCAD\}}
* On Mac OSX it is usually {{incode|/Applications/FreeCAD/}}


The {{incode|$ROOT_DIR}} could be a particular user's directory.
Această secțiune prezintă cum se localizează folderul conținând macrocomenzi FreeCAD.
* On Linux it is usually {{incode|/home/username/.FreeCAD/}}
* On Windows it is usually {{incode|C:\Users\username\Application Data\FreeCAD\}}
* On Mac OSX it is usually {{incode|/Users/username/Library/Preferences/FreeCAD/}}


<div class="mw-translate-fuzzy">
'''1 :''' click '''Menu > Macro > Macros''' (which has the icon [[File:Std DlgMacroExecuteDirect.svg|24px]] and the tool tip "Open a dialog to let you execute a recorded macro")
'''1 :''' click '''Menu > Macro > Macros''' (which has the icon [[File:Std DlgMacroExecuteDirect.svg|24px]] and the tool tip "Open a dialog to let you execute a recorded macro")
</div>


<div class="mw-translate-fuzzy">
[[File:Dxf_Importer_Install_01.png|640px|center]]
[[File:Dxf_Importer_Install_01.png|640px|center]]
</div>


<div class="mw-translate-fuzzy">
'''2 :''' This will open a dialog box

'''3 :''' The address of "Macro destination" ('''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''' in the screen snapshot below)
'''3 :''' The address of "Macro destination" ('''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''' in the screen snapshot below)
* Windows: the form is usually '''drive:\Users\your_user_name\AppData\Roaming\FreeCAD\'''
* Windows: the form is usually '''drive:\Users\your_user_name\AppData\Roaming\FreeCAD\'''
* Ubuntu: the form is usually '''/home/your_user_name/.FreeCAD'''
* Ubuntu: the form is usually '''/home/your_user_name/.FreeCAD'''
* Macintosh: the form is usually "/Users/your_user_name/Library/Preferences/FreeCAD"
* Macintosh: the form is usually "/Users/your_user_name/Library/Preferences/FreeCAD"
</div>


<div class="mw-translate-fuzzy">
'''4 :''' copy the address of "Macro destination" (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''')

[[File:Dxf_Importer_Install_02.png|640px|center]]
[[File:Dxf_Importer_Install_02.png|640px|center]]
</div>


<div class="mw-translate-fuzzy">
'''5 :''' View the macro folder by:
'''5 :''' View the macro folder by:
* Windows: paste the address into your File explorer and confirm
* Windows: paste the address into your File explorer and confirm
* Macintosh: locate the folder in the Finder or paste the address into a File explorer (remember the "file:///" prefix in the File explorer for a file on disk)
* Macintosh: locate the folder in the Finder or paste the address into a File explorer (remember the "file:///" prefix in the File explorer for a file on disk)
</div>


<div class="mw-translate-fuzzy">
[[File:Dxf_Importer_Install_03.png|640px|center]]
[[File:Dxf_Importer_Install_03.png|640px|center]]
</div>


<div class="mw-translate-fuzzy">
'''6 :''' Access the files by:
'''6 :''' Access the files by:
*Windows: leave open the file explorer
*Windows: leave open the file explorer
*Macintosh: either leave a Finder window open, or bookmark the location in your File explorer, or set up an Alias to point to it, or drag the folder into the SideBar of the Finder so it is there to use from other programs such as text editors etc. (Note: version 0.14 of FreeCAD does not support Aliases but does support the SideBar)
*Macintosh: either leave a Finder window open, or bookmark the location in your File explorer, or set up an Alias to point to it, or drag the folder into the SideBar of the Finder so it is there to use from other programs such as text editors etc. (Note: version 0.14 of FreeCAD does not support Aliases but does support the SideBar)
</div>


<div class="mw-translate-fuzzy">
[[File:Dxf_Importer_Install_04.png|640px|center]]
[[File:Dxf_Importer_Install_04.png|640px|center]]
{{clear}}
{{clear}}
</div>


{{clear}}
</div>
</div>


== Installing macros ==
'''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">


=== Automatic method ===
==The indentation errors examples wrong code==
<div class="mw-collapsible-content">


Starting with FreeCAD 0.17, use the [[Addon Manager|Addon Manager]] in {{MenuCommand|Tools → Addon manager}} to install a macro that has been included in the [https://github.com/FreeCAD/FreeCAD-macros FreeCAD-macros] repository.
Indentarea în programarea python este foarte importantă și este parte integrantă a codului, un spațiu sau o schimbare necorespunzătoare provoacă o eroare de indentare ex:


<div class="mw-collapsible-content">
<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'))'''
</span>


In past versions of FreeCAD you could use two automated ways to install macros and other addons:
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.
* [https://github.com/FreeCAD/FreeCAD-addons addons_installer.FCMacro]: itself a macro, this was the precursor to the Addon Manager, and is hosted in the [https://github.com/FreeCAD/FreeCAD-addons FreeCAD-addons] repository. You don't need to use this tool in new installations of FreeCAD.

* [https://github.com/microelly2/freecad-pluginloader freecad-pluginloader]: also a macro, it could be used to install new components to FreeCAD. It is no longer developed.
'''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.

[[Image:Macro Install HowTo 09.png|center|the code was stuck without any indentation]]

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


The recommended way to install addons, that is, [[external workbenches|external workbenches]] and macros, is the [[Addon Manager|Addon Manager]]. However, you can still add macros to your system with the manual methods described in the following sections; this is useful if you are developing and testing your own code.
[[Image:Macro Install HowTo 10.png|center|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

[[Image:Macro Install HowTo 11.png|center|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'''

[[Image:Macro Install HowTo 12.png|center|remove one space all lines]]

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

[[Image:Macro Install HowTo 14.png|center|640px|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

[[Image:Macro Install HowTo 15.png|center|640px|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 [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

[[Image:Macro Install HowTo 16.png|center|640px|You must delete all the extra space]]

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

[[Image:Macro_Install_HowTo_29.png|center|640px|Here the selection also take the column numbers]]

'''9 :''' Perfect code.

[[Image:Macro Install HowTo 13.png|center|Perfect code]]

<br />
</div>
</div>
</div>
</div>


<div class="toccolours mw-collapsible mw-collapsed">
'''Method 1:'''


<div class="mw-translate-fuzzy">
<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==
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
</div>


For macros that are relatively small, 300 lines or less, the code can be copied and pasted directly into the FreeCAD macro editor.
For example we will copy the macro [[File:Part_Prism_Apothem.svg|16px]] [[Macro_Apothem_Based_Prism_GUI|Macro_Apothem_Based_Prism_GUI]]


<div class="mw-collapsible-content">

We will use [[Image:Part_Prism_Apothem.svg|24px]] [[Macro_Apothem_Based_Prism_GUI|Macro Apothem Based Prism GUI]] as an example.

<div class="mw-translate-fuzzy">
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_Toolbars|toolbar.]]
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_Toolbars|toolbar.]]
</div>


If there is a custom icon download it; click on it with the right mouse button and select {{incode|Save image as...}}; place the icon in the macros directory. This icon can be used as a shortcut for the macro in a [[Customize_Toolbars|custom toolbar]]. The default icon is [[Image:Text-x-python.png|24px]].

<div class="mw-translate-fuzzy">
[[File:Macro Install HowTo 28.png|300px|center|Download icon]]
[[File:Macro Install HowTo 28.png|300px|center|Download icon]]
</div>


<div class="mw-translate-fuzzy">
After copying your code we will paste the code in FreeCAD editor.
After copying your code we will paste the code in FreeCAD editor.
</div>


<div class="mw-translate-fuzzy">
'''1 :''' Open FreeCAD and open the editor in FreeCAD
'''1 :''' Open FreeCAD and open the editor in FreeCAD
</div>


<div class="mw-translate-fuzzy">
[[File:Dxf_Importer_Install_01.png|640px|center]]
[[File:Dxf_Importer_Install_01.png|640px|center]]
</div>


<div class="mw-translate-fuzzy">
'''2 :''' The window macros file opens, click {{KEY|Create}} button
'''2 :''' The window macros file opens, click {{KEY|Create}} button
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''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
</div>


<div class="mw-translate-fuzzy">
[[File:Macro Install HowTo 18.png|300px|center|enter the macro name]]
[[File:Macro Install HowTo 18.png|300px|center|enter the macro name]]
</div>


<div class="mw-translate-fuzzy">
'''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.
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''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.
</div>


<div class="mw-translate-fuzzy">
[[File:Macro Install HowTo 20.png|640px|center|close the window]]
[[File:Macro Install HowTo 20.png|640px|center|close the window]]
</div>


<div class="mw-translate-fuzzy">
'''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}}
</div>


Restart FreeCAD to correctly register the new macro.
'''PS:''' For the change silk consideration must save the macro and reopen it and just run it.


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''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}}
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''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
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
9 : The macro returns an error ! we do not have to open document, open a document [[File:Document-new.svg|24px]] 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 [[File:Document-new.svg|24px]] and repeat the operation '''7''' and '''8'''. Some macros open a new document if it does not find one.
</div>


Create a new document with {{MenuCommand|File → [[Image:Std_New.svg|16px]] [[Std_New|New]]}}, and then repeat the previous steps to execute the macro.

<div class="mw-translate-fuzzy">
[[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!]]
</div>


<div class="mw-translate-fuzzy">
10 : Here is your prism
10 : Here is your prism
</div>


<div class="mw-translate-fuzzy">
[[File:Macro Install HowTo 24.png|640px|center|your prism]]
[[File:Macro Install HowTo 24.png|640px|center|your prism]]
</div>


<div class="mw-translate-fuzzy">
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
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
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
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


</div>
</div>
</div>
</div>


<div class="toccolours mw-collapsible mw-collapsed">
'''Method 2:'''


<div class="mw-translate-fuzzy">
<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==
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
</div>


<div class="mw-translate-fuzzy">
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]])
</div>


<div class="mw-collapsible-content">
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]


We will use [[Image:Text-x-python.png|24px]] [[Macro_screw_maker1_2|Macro screw maker]] as an example.
For Linux use this on the terminal

1. Download the compressed code from the forum, [http://forum.freecadweb.org/viewtopic.php?f=22&t=6558#p52887 Screw Maker].

<div class="mw-translate-fuzzy">
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]
</div>


{{Code|code=
{{Code|code=
Line 193: Line 292:
}}
}}


<div class="mw-translate-fuzzy">
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'''
'''1 :''' Download your file in your local folder here the folder '''Temp'''
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''2 :''' Unzip your file in the folder.
'''2 :''' Unzip your file in the folder.
</div>


<div class="mw-translate-fuzzy">
[[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.
]]
]]
</div>


<div class="mw-translate-fuzzy">
'''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
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''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'''.
</div>


<div class="mw-translate-fuzzy">
[[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]]
</div>


<div class="mw-translate-fuzzy">
'''5 :''' Return to your File explorer remained open in the macro location (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''') and close the File explorer.
'''5 :''' Return to your File explorer remained open in the macro location (here '''C:\Users\your_user_name\AppData\Roaming\FreeCAD\''') and close the File explorer.
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 05.png|center|640px|Return to your File explorer remained open]]
[[Image:Macro Install HowTo 05.png|center|640px|Return to your File explorer remained open]]
</div>


<div class="mw-translate-fuzzy">
'''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"
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 06.png|center|640px|Open FreeCAD]]
[[Image:Macro Install HowTo 06.png|center|640px|Open FreeCAD]]
</div>


<div class="mw-translate-fuzzy">
'''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}}
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 07.png|center|640px|The macros window open]]
[[Image:Macro Install HowTo 07.png|center|640px|The macros window open]]
</div>


<div class="mw-translate-fuzzy">
'''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
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 08.png|center|640px|Your macro is executed]]
[[Image:Macro Install HowTo 08.png|center|640px|Your macro is executed]]
</div>


<div class="mw-translate-fuzzy">
'''9''' : Whaouu
[[Image:Macro Install HowTo 30.png|center|640px|Whaouu]]
</div>


</div>
[[Image:Macro Install HowTo 30.png|center|640px|Whaouu]]
</div>

== Execute a macro in command line ==

<div class="toccolours mw-collapsible mw-collapsed">

Command line execute a macro (.FCMacro or .py)

<div class="mw-collapsible-content">

on Windows

{{Code|code=
"C:\Program Files\FreeCAD\bin\FreeCAD.exe" "C:\Users\userName\AppData\Roaming\FreeCAD\Mod\WorkFeature\start_WF.FCMacro"
}}

on Linux

{{Code|code=
todo
}}


</div>
</div>
</div>
</div>


== Errors in macros ==
'''Section if the text are not display:'''


<div class="toccolours mw-collapsible mw-collapsed">

<div class="mw-translate-fuzzy">
==The indentation errors examples wrong code==
<div class="mw-collapsible-content">
</div>

<div class="mw-translate-fuzzy">
Indentarea în programarea python este foarte importantă și este parte integrantă a codului, un spațiu sau o schimbare necorespunzătoare provoacă o eroare de indentare de ex,:
</div>

This section describes some errors that may be encountered when copying and pasting, and writing macro code.

<div class="mw-collapsible-content">

<div class="mw-translate-fuzzy">
<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'))'''
</span>
</div>

{{Code|code=
<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'))
}}

<div class="mw-translate-fuzzy">
'''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.
</div>

If the code lacks any indentation, the code won't work. Class ({{incode|class}}) and function definitions ({{incode|def()}}), as well as control structures ({{incode|if}}, {{incode|while}}, {{incode|for}}) should be followed by a block of indented code.

This error is possible if the user doesn't copy the code correctly, and all spaces are accidentally removed.

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 09.png|center|the code was stuck without any indentation]]
</div>

<div class="mw-translate-fuzzy">
'''2 :''' the code was correct indentations in the right place.
</div>

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 10.png|center|the code was correct indentations in the right place]]
</div>

<div class="mw-translate-fuzzy">
'''3 :''' we select the code, and we see that the selection is at the edge of the code, the macro must works so good
</div>

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 11.png|center|the macro must works so good]]
</div>

<div class="mw-translate-fuzzy">
'''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'''
</div>

If an additional space is introduced at the beginning of all lines, the Python interpreter will fail and complain about unnecessary indentation. In this case, all lines need the initial space removed.

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 12.png|center|remove one space all lines]]
</div>

<div class="mw-translate-fuzzy">
'''5 :''' Here the code has been copied in a forum window with the {{KEY|Select all}} button apparently the selection is good
</div>

Here the code has been copied from a forum thread by using the {{Button|Select all}} button. Apparently the selection is good.

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 14.png|center|640px|Here the code has been copied in a forum]]
</div>

<div class="mw-translate-fuzzy">
'''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
</div>

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 15.png|center|640px|But the selection pasted into the FreeCAD editor gives a surprise]]
</div>

<div class="mw-translate-fuzzy">
'''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
</div>

In Windows, [http://notepad-plus-plus.org/ Notepad++] can perform selection with {{KEY|Alt}} + Mouse dragging, and then use {{MenuCommand|Edit → Indent → Decrease the indentation}}.

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 16.png|center|640px|You must delete all the extra space]]
</div>

<div class="mw-translate-fuzzy">
'''8 :''' Here the selection also take the column numbers which will also give an error
</div>

Here the selection also selects the line numbers in the code example. If this selection is pasted into the macro editor, it won't work. All line numbers need to be removed, and the spaces adjusted so that the Python code has the proper indentation.

<div class="mw-translate-fuzzy">
[[Image:Macro_Install_HowTo_29.png|center|640px|Here the selection also take the column numbers]]
</div>

<div class="mw-translate-fuzzy">
'''9 :''' Perfect code.
</div>

<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 13.png|center|Perfect code]]
</div>

</div>
</div>

<div class="toccolours mw-collapsible mw-collapsed">

<div class="mw-translate-fuzzy">
<div class="toccolours mw-collapsible mw-collapsed">
<div class="toccolours mw-collapsible mw-collapsed">
==For those who see no information is displayed.==
==For those who see no information is displayed.==
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
Some macros display information on the screen in general they are displayed in the report view.
Some macros display information on the screen in general they are displayed in the report view.
</div>


Macros may output information to the report view to detail what the code is doing when it is running.
FreeCAD use two methods to display the information in the window view report.


If no information is displayed, make sure the report view and [[Python|Python]] console are visible, and that the output is directed tot he report view.

<div class="mw-collapsible-content">

==== Printing information ====
FreeCAD macros have two methods to print information to the report view.

<div class="mw-translate-fuzzy">
'''1 : Commands'''
'''1 : Commands'''
</div>

{{Code|code=
{{Code|code=
FreeCAD.Console.PrintMessage("Hello World! \n")
App = FreeCAD
App.Console.PrintMessage ("Hello World ! \n")
FreeCAD.Console.PrintError("Hello World! \n")
App.Console.PrintError ("Hello World ! \n")
FreeCAD.Console.PrintWarning("Hello World! \n")
App.Console.PrintWarning ("Hello World ! \n")
}}
}}

<div class="mw-translate-fuzzy">
or
or
</div>

{{Code|code=
{{Code|code=
FreeCAD.Console.PrintMessage ("Hello World ! \n")
print("Hello World!")
FreeCAD.Console.PrintError ("Hello World ! \n")
FreeCAD.Console.PrintWarning ("Hello World ! \n")
}}
or
{{Code|code=
print "Hello World !"
}}
}}

<div class="mw-translate-fuzzy">
To see the information displayed in the console you should:
To see the information displayed in the console you should:
</div>


<div class="mw-translate-fuzzy">
'''1 :''' Open FreeCAD
'''1 :''' Open FreeCAD
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 31.png|center|640px|Open FreeCAD]]
[[Image:Macro Install HowTo 31.png|center|640px|Open FreeCAD]]
</div>


<div class="mw-translate-fuzzy">
'''2 :''' Click the '''View menu''' and '''Views'''
[[Image:Macro Install HowTo 32.png|center|640px|Click the View menu and Views]]

</div>
[[Image:Macro Install HowTo 32.png|center|640px|Click the View menu and Views]]


<div class="mw-translate-fuzzy">
'''3 :''' Check '''Report View''' and '''Python Console'''
'''3 :''' Check '''Report View''' and '''Python Console'''
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 33.png|center|640px|Check Report View and Python Console]]
[[Image:Macro Install HowTo 33.png|center|640px|Check Report View and Python Console]]
</div>


<div class="mw-translate-fuzzy">
'''4 :''' the windows are enabled and available commands like "'''App.Console.PrintMessage'''" is configured to the "Report View"
'''4 :''' the windows are enabled and available commands like "'''App.Console.PrintMessage'''" is configured to the "Report View"
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 34.png|center|640px|Hello World!]]
[[Image:Macro Install HowTo 34.png|center|640px|Hello World!]]

</div>


<div class="mw-translate-fuzzy">
'''2 : command "print" which is a Python command.'''
'''2 : command "print" which is a Python command.'''
</div>


<div class="mw-translate-fuzzy">
It is possible that this command does not display the expected string.

For information to be displayed in the window do this :

'''1 :''' Click the '''Edit menu''' and then '''Preferences'''
'''1 :''' Click the '''Edit menu''' and then '''Preferences'''
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 35.png|center|640px|Edit menu]]
[[Image:Macro Install HowTo 35.png|center|640px|Edit menu]]
</div>


<div class="mw-translate-fuzzy">
'''2 :''' In the new window, click '''General''', and select the '''Output window''' tab
'''2 :''' In the new window, click '''General''', and select the '''Output window''' tab
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 36.png|center|640px|General]]
[[Image:Macro Install HowTo 36.png|center|640px|General]]
</div>


<div class="mw-translate-fuzzy">
'''3 :''' check both boxes:
'''3 :''' check both boxes:
</div>


<div class="mw-translate-fuzzy">
[[Image:Case_a_cocher_O.png|16px]] Redirect internal Python output to Report view
[[Image:Case_a_cocher_O.png|16px]] Redirect internal Python output to Report view
</div>


<div class="mw-translate-fuzzy">
[[Image:Case_a_cocher_O.png|16px]] Redirect internal Python errors to Report view
[[Image:Case_a_cocher_O.png|16px]] Redirect internal Python errors to Report view
</div>


<div class="mw-translate-fuzzy">
and click the {{KEY|OK}} button
and click the {{KEY|OK}} button
</div>


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 37.png|center|640px|Redirect internal]]
[[Image:Macro Install HowTo 37.png|center|640px|Redirect internal]]

</div>
'''4 :''' the setup is complete you should see all.

[[Image:Macro Install HowTo 38.png|center|640px|the setup is complete]]


<div class="mw-translate-fuzzy">
[[Image:Macro Install HowTo 38.png|center|640px|the setup is complete]]
</div>
</div>
</div>
</div>
</div>


{{Powerdocnavi{{#translation:}}}}
End tutorial good job.
[[Category:Developer Documentation{{#translation:}}]]

[[Category:Python Code{{#translation:}}]]
==Legături==
{{clear}}

Macro addon-uri [https://github.com/FreeCAD/FreeCAD-addons addons_installer.FCMacro] pentru o instalare facilă a macrocenzilor.

Alt macro ușor de instalare macro freecad-pluginloader

Pagina [[Macros_recipes|Macros recipes]] vă dă o serie de macrocomenzi

Revision as of 19:28, 22 June 2020

Tutorial
Topic
Programming
Level
Medium programmer
Time to complete
15 minutes
Authors
Mario52
FreeCAD version
All
Example files
None
See also
None

Descriere

Acest tutorial scurt vă va arăta cum să instalați și să utilizați macrocomenzile FreeCAD.

Since v0.17 it is easy to add macros by using the Addon Manager. A regular user doesn't need to do more than use this tool. Keep reading for more information regarding installation of macros.

Macros are sequences of commands which are used to perform a complex drawing operation. Macros are Python scripts, which means they are text files that can be written and edited with a text editor.

While Python scripts normally have the .py extension, FreeCAD macros should have the .FCMacro extension. A collection of macros written by experienced users is found in the macros recipes page.

See Introduction to Python to learn about the Python programming language, and then Python scripting tutorial and FreeCAD Scripting Basics to learn about writing macros.

Here is a video on installing FreeCAD macros in Ubuntu.

Meniul Macro Menu și Iconițele Instrumentelor

Menu

Besides the tools in the toolbar, the following functions are also available in the Macro menu.

Locația și destinația mcrocomanzilor

Macros are created in a specific folder under the user's FreeCAD directory. This directory can be configured in the Execute macro dialog, or in the Preferences Editor, through the menu Edit → Preferences → General → Macro → Macro recording settings.

Downloaded macros should also be placed in this directory.

Default directory

Macros can be simply copied into

$ROOT_DIR/

where $ROOT_DIR is a top level directory searched by FreeCAD on startup.

The $ROOT_DIR could be a system wide directory, in which case the macro is installed for all users.

  • On Linux it is usually /usr/share/freecad/
  • On Windows it is usually C:\Program Files\FreeCAD\
  • On Mac OSX it is usually /Applications/FreeCAD/

The $ROOT_DIR could be a particular user's directory.

  • On Linux it is usually /home/username/.FreeCAD/
  • On Windows it is usually C:\Users\username\Application Data\FreeCAD\
  • On Mac OSX it is usually /Users/username/Library/Preferences/FreeCAD/

1 : click Menu > Macro > Macros (which has the icon and the tool tip "Open a dialog to let you execute a recorded macro")

3 : The address of "Macro destination" (C:\Users\your_user_name\AppData\Roaming\FreeCAD\ in the screen snapshot below)

  • Windows: the form is usually drive:\Users\your_user_name\AppData\Roaming\FreeCAD\
  • Ubuntu: the form is usually /home/your_user_name/.FreeCAD
  • Macintosh: the form is usually "/Users/your_user_name/Library/Preferences/FreeCAD"

5 : View the macro folder by:

  • Windows: paste the address into your File explorer and confirm
  • Macintosh: locate the folder in the Finder or paste the address into a File explorer (remember the "file:///" prefix in the File explorer for a file on disk)

6 : Access the files by:

  • Windows: leave open the file explorer
  • Macintosh: either leave a Finder window open, or bookmark the location in your File explorer, or set up an Alias to point to it, or drag the folder into the SideBar of the Finder so it is there to use from other programs such as text editors etc. (Note: version 0.14 of FreeCAD does not support Aliases but does support the SideBar)

Installing macros

Automatic method

Starting with FreeCAD 0.17, use the Addon Manager in Tools → Addon manager to install a macro that has been included in the FreeCAD-macros repository.

In past versions of FreeCAD you could use two automated ways to install macros and other addons:

  • addons_installer.FCMacro: itself a macro, this was the precursor to the Addon Manager, and is hosted in the FreeCAD-addons repository. You don't need to use this tool in new installations of FreeCAD.
  • freecad-pluginloader: also a macro, it could be used to install new components to FreeCAD. It is no longer developed.

The recommended way to install addons, that is, external workbenches and macros, is the Addon Manager. However, you can still add macros to your system with the manual methods described in the following sections; this is useful if you are developing and testing your own code.

Method copy the code in one window and paste in the FreeCAD editor

For macros that are relatively small, 300 lines or less, the code can be copied and pasted directly into the FreeCAD macro editor.

We will use Macro Apothem Based Prism GUI as an example.

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 toolbar.

If there is a custom icon download it; click on it with the right mouse button and select Save image as...; place the icon in the macros directory. This icon can be used as a shortcut for the macro in a custom toolbar. The default icon is .

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

Restart FreeCAD to correctly register the new macro.

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.

Create a new document with File → New, and then repeat the previous steps to execute the macro.

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 macro in a compressed .ZIP file

Download the file compressed here (example) Macro_screw_maker 1.7. (the page Macro_screw_maker)

We will use Macro screw maker as an example.

1. Download the compressed code from the forum, Screw Maker.

Free for Windows 7-zip ou L-Zarc ou quickzip

unzip your_file.zip -d your_directory

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 File explorer remained open in the macro location (here C:\Users\your_user_name\AppData\Roaming\FreeCAD\) and close the File explorer.

Return to your File explorer remained open
Return to your File explorer 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
Whaouu
Whaouu

Execute a macro in command line

Command line execute a macro (.FCMacro or .py)

on Windows

"C:\Program Files\FreeCAD\bin\FreeCAD.exe" "C:\Users\userName\AppData\Roaming\FreeCAD\Mod\WorkFeature\start_WF.FCMacro"

on Linux

todo

Errors in macros

The indentation errors examples wrong code

Indentarea în programarea python este foarte importantă și este parte integrantă a codului, un spațiu sau o schimbare necorespunzătoare provoacă o eroare de indentare de ex,:

This section describes some errors that may be encountered when copying and pasting, and writing macro code.

<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'))

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.

If the code lacks any indentation, the code won't work. Class (class) and function definitions (def()), as well as control structures (if, while, for) should be followed by a block of indented code.

This error is possible if the user doesn't copy the code correctly, and all spaces are accidentally removed.

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

If an additional space is introduced at the beginning of all lines, the Python interpreter will fail and complain about unnecessary indentation. In this case, all lines need the initial space removed.

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 from a forum thread by using 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

In Windows, Notepad++ can perform selection with Alt + Mouse dragging, and then use 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 selects the line numbers in the code example. If this selection is pasted into the macro editor, it won't work. All line numbers need to be removed, and the spaces adjusted so that the Python code has the proper indentation.

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

9 : Perfect code.

Perfect code
Perfect code

For those who see no information is displayed.

Some macros display information on the screen in general they are displayed in the report view.

Macros may output information to the report view to detail what the code is doing when it is running.

If no information is displayed, make sure the report view and Python console are visible, and that the output is directed tot he report view.

Printing information

FreeCAD macros have two methods to print information to the report view.

1 : Commands

FreeCAD.Console.PrintMessage("Hello World! \n")
FreeCAD.Console.PrintError("Hello World! \n")
FreeCAD.Console.PrintWarning("Hello World! \n")

or

print("Hello World!")

To see the information displayed in the console you should:

1 : Open FreeCAD

Open FreeCAD
Open FreeCAD
Click the View menu and Views
Click the View menu and Views

3 : Check Report View and Python Console

Check Report View and Python Console
Check Report View and Python Console

4 : the windows are enabled and available commands like "App.Console.PrintMessage" is configured to the "Report View"

Hello World!
Hello World!

2 : command "print" which is a Python command.

1 : Click the Edit menu and then Preferences

Edit menu
Edit menu

2 : In the new window, click General, and select the Output window tab

General
General

3 : check both boxes:

Redirect internal Python output to Report view

Redirect internal Python errors to Report view

and click the OK button

Redirect internal
Redirect internal
the setup is complete
the setup is complete