Tools>Customize>Macros in user.cfg

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Tools>Customize>Macros in user.cfg

Post by drmacro »

@chennes

When the Tools>Customize>Macros is used to define a macro for use in toolbars the following is created in user.cfg:

Code: Select all

      <FCParamGroup Name="Macro">
          <FCParamGroup Name="Macros">
            <FCParamGroup Name="Std_Macro_0">
                <FCText Name="Script">Snip.FCMacro</FCText>
                <FCText Name="Menu">Screen Cap</FCText>
                <FCText Name="Tooltip"></FCText>
                <FCText Name="WhatsThis"></FCText>
                <FCText Name="Statustip"></FCText>
                <FCText Name="Pixmap">camera-photo</FCText>
                <FCText Name="Accel"></FCText>
                <FCBool Name="System" Value="0"/>
            </FCParamGroup>
          </FCParamGroup>
If I run Python code to enter the above into the user.cfg and then view it with Tools>Edit parameters it can be seen in the parameters. But, if FreeCAD is shutdown at that point this param group is not saved in user.cfg.

Is there some way to trigger this to be persisted?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Tools>Customize>Macros in user.cfg

Post by chennes »

Are you using FreeCADGui.Command.createCustomCommand to do it?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Tools>Customize>Macros in user.cfg

Post by Roy_043 »

Try:

Code: Select all

FreeCAD.saveParameter()
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Tools>Customize>Macros in user.cfg

Post by drmacro »

Roy_043 wrote: Sun Sep 18, 2022 3:59 pm Try:

Code: Select all

FreeCAD.saveParameter()
I assume this does the same thing the "Save to disk" button does in the Parameters dialog does.

Both that button and this command saves the current state of the params to user.cfg. (i.e. with FC open after issuing this command, I open user.cfg in an editor, the param group is there. If I then close FC, the param group is not in user.cfg.)

One thing I've noted is that after the param group has been added (and before closing FC) the new macro definition does not show up in the Tool>Customize>Macros dialog. But, creating a macro in said dialog will persist the the one created in the dialog overwriting the the one added programmatically.
chennes wrote: Sun Sep 18, 2022 3:50 pm Are you using FreeCADGui.Command.createCustomCommand to do it?
No, I'm attempting to add the macro with a PP.
I originally had the code to write this param group in PP post.FCMacro. I have written code to add the TUX Persistent toolbars and then added code for this param group since it apparently does not get written by the PP apply process. I have since isolated the code into a Python files so I could debug it.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Tools>Customize>Macros in user.cfg

Post by chennes »

If you want to see how the Addon Manager does it, that code is about here:
https://github.com/FreeCAD/FreeCAD/blob ... ar.py#L232
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Tools>Customize>Macros in user.cfg

Post by drmacro »

chennes wrote: Sun Sep 18, 2022 5:48 pm If you want to see how the Addon Manager does it, that code is about here:
https://github.com/FreeCAD/FreeCAD/blob ... ar.py#L232
I think I see where this code adds and a macro to a toolbar. Even where it forces the toolbars to reload.

But, I'm not seeing the creation of the actual macro. I'm talking about what this dialog does:
CustomizeDialog.png
CustomizeDialog.png (44.49 KiB) Viewed 1217 times
I think that code is adding an existing to this toolbar?
MacrosToolbar.png
MacrosToolbar.png (38.49 KiB) Viewed 1217 times
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Tools>Customize>Macros in user.cfg

Post by chennes »

It's really both rolled into one -- it doesn't "create" the macro, in the sense that the actual FCMacro file must already exist, but it creates that section of the CFG file that you quoted above. It's doing that in the call to FreeCADGui.Command.createCustomCommand, which creates the command. The code that's adding that to the toolbar is the next line, toolbar.SetString(command_name, "FreeCAD"), though to make that line work there's a large amount of setup work a priori creating that toolbar (which is basically all the rest of that file does).
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Tools>Customize>Macros in user.cfg

Post by drmacro »

chennes wrote: Sun Sep 18, 2022 7:01 pm It's really both rolled into one -- it doesn't "create" the macro, in the sense that the actual FCMacro file must already exist, but it creates that section of the CFG file that you quoted above. It's doing that in the call to FreeCADGui.Command.createCustomCommand, which creates the command. The code that's adding that to the toolbar is the next line, toolbar.SetString(command_name, "FreeCAD"), though to make that line work there's a large amount of setup work a priori creating that toolbar (which is basically all the rest of that file does).
After looking at that code for a while I see pretty much what is does. I even got FreeCADGui.Command.createCustomCommand to return.

But, the real question is why, even after the param group is written to the .cfg is closing FC throwing it away?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Tools>Customize>Macros in user.cfg

Post by chennes »

It's similar to what was happening with the toolbars: when FreeCAD exits, it is basically overwriting the config data with the "actual" data, asking the Command Manager for its list of commands and storing that.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Tools>Customize>Macros in user.cfg

Post by drmacro »

chennes wrote: Sun Sep 18, 2022 7:57 pm It's similar to what was happening with the toolbars: when FreeCAD exits, it is basically overwriting the config data with the "actual" data, asking the Command Manager for its list of commands and storing that.
I'm going to step away from this for a while.

Thanks for all the help.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply