Macro store locations

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
AtD
Posts: 50
Joined: Mon Mar 18, 2019 7:14 am

Macro store locations

Post by AtD »

Hi,
Just one simple questions: is it possible, as the GUI suggests, that we have a user and a system macro location?
If yes, where is this system macro location? I searched on google but was unable to find anything.

My team members and me are working on many geometries. We have macros that are "static" and everyone runs them in the same version. Then we have macros, which are specific for a certain geometry.
The static macros are attached to a toolbar in the GUI so we can quickly access them. Problem is, once we change the macro location in the settings to access the geometry-specific macros, the attached macros at the toolbar are no longer found.
Is there a way to have some macros in a static directory (system macros) and other in a user directory? How the GUI is designed, tells me that someone intended it that way, but I dont know how it works.

Thanks for any hints.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Macro store locations

Post by sgrogan »

AtD wrote: Thu Dec 09, 2021 11:06 am Just one simple questions: is it possible, as the GUI suggests, that we have a user and a system macro location?
If yes, where is this system macro location?
What OS are you on?
"fight the good fight"
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Macro store locations

Post by TheMarkster »

Enter into the python console:

Code: Select all

App.getHomePath()
Navigate to that folder and create a new folder in it called 'Macro'. Place a few macros into there. Now when you open the Macros dialog and click the system tab you will see these macros in that HomePath/Macro folder.

I put one in my folder named search.FCMacro:
Snip macro screenshot-ee2d75.png
Snip macro screenshot-ee2d75.png (16.43 KiB) Viewed 2542 times
Once you execute it you can run it again via the Recent Macros menu.

You can also add it to a toolbar. The system macros will appear at the bottom (actually the top) of the list in the customize dialog. This will enable you to have 2 folders for macros. Another use for this could be to have some commonly used macros in that tab if you have a lot of macros that require a lot of scrolling to find.

But there is a down side. For me (on windows) the folder is in the folder that 7-zip creates when extracting a new weekly build. I update to a new weekly build by deleting the old folder after extracting the new .7z file into the new one. The new folder then becomes the new home folder. I would need to take care not to also delete that macro folder when updating to a newer weekly build, and I would also need to move the Macro folder into the new home folder.
AtD
Posts: 50
Joined: Mon Mar 18, 2019 7:14 am

Re: Macro store locations

Post by AtD »

Sorry I didnt mention my os, I am on Windows.

Thanks alot for your answer TheMarkster, this is exactly what I was looking for. I tested it, and it works nicely.
I can see the downside, but its not so important for me. We tend to use a constant version as long as possible and don't regularly update to newer builds. In case we do, I will keep in mind to look for the macros.
So, thank you again!

To me it seems to be a bug, that macros that are attached to a toolbar shortcut are dependent on the setting of the macro folder, but "recent macros" are not. Should I open a bug report for that?
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Macro store locations

Post by onekk »

What type of installation are you using in Windows "Portable Builds" or "Installer", even this thing should be known by developers or "power users".

As example there are some "SYSTEM VARIABLES" that could be set to modify user directory and maybe places where FreeCAD is searching for things.

But they are managed differently as in Windows you have the "Registry" that when using a "Portable Build" is not touched, so answer could differ based on installation methods.

On Linux I use three version of FreeCAD with three user directory that not interfere between them, but i could use symlinks to place Macro in a common directory where they effectively reside, but Macros are Spread across different installation. Windows as a similar mechanism, so so maybe you could place some symlinks to "net mounted" directories, if you don't have problem to properly set access permission.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Macro store locations

Post by mario52 »

Hi

tested in "C:/Temp/Testéééèèçç/CloneConvert.FCMacro" and other directory and run well

open run and close the macroEditor totally hidden for the user

just cretate the bouton

Code: Select all

import FreeCADGui
FreeCADGui.open(u"Complete_Path_of_The_Macro/MacroYouUse.FCMacro")
Gui.SendMsgToActiveView("Run")
Gui.runCommand('Std_CloseActiveWindow',0)

(inspired by the Triplus idea GUI improvement request : Save & Run Button)

mario
Last edited by mario52 on Fri Dec 10, 2021 1:09 pm, edited 1 time in total.
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
drmacro
Veteran
Posts: 8984
Joined: Sun Mar 02, 2014 4:35 pm

Re: Macro store locations

Post by drmacro »

I have long wondered about the Macro dialog and how it displays the macro directory.

If, for example, you have multiple versions running out the <build directory>/bin, then

Code: Select all

App.getHomePath()
returns the <build directory>

But,

Code: Select all

App.getUserMacroDir()
the return is (on Linux) ~/.local/share/FreeCAD/Macro/

But, if Parameters Macro>MacroPath is set then the dialog shows the macros there. (In my case set to a network drive, which is not represented by any of the directories returned by the above Python methods) so all my machines access a single source for Python/macro files.)

Since the dialog apparently looks only the specified directory and not subdirectories it doesn't allow for much organization of the user macros. They all must reside in a single level and become a huge list. (I suppose this is not to much of a problem for the typical user who only has a limited number of macros/Python files...)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Macro store locations

Post by TheMarkster »

Code: Select all

App.getUserMacroDir() 
does not return the correct directory for me. It gives the default directory instead, but I changed it in the dialog to put them in my documents folder.

Instead, use:

Code: Select all

App.ParamGet("User parameter:BaseApp/Preferences/Macro").GetString("MacroPath", App.getUserMacroDir())
Syres
Veteran
Posts: 2900
Joined: Thu Aug 09, 2018 11:14 am

Re: Macro store locations

Post by Syres »

TheMarkster wrote: Fri Dec 10, 2021 4:48 pm

Code: Select all

App.getUserMacroDir() 
does not return the correct directory for me. It gives the default directory instead, but I changed it in the dialog to put them in my documents folder.
You are correct, IMHO the correct syntax is:

Code: Select all

App.getUserMacroDir(True)
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Macro store locations

Post by TheMarkster »

Thanks for this. I did not think to check the documentation.

Code: Select all

help(App.getUserMacroDir)
Help on built-in function getUserMacroDir in module FreeCAD:

getUserMacroDir(...)
getUserMacroDir(bool=False) -> stringGet the directory of the user's macro directory
If parameter is False (the default) it returns the standard path in theuser's home directory, otherwise it returns the user-defined path.
Post Reply