How about a new "Command" addon type ?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

How about a new "Command" addon type ?

Post by openBrain »

I'm wondering if community would find useful to have a new "Command" addon type and mechanism.

The goal would be to provide an integration mechanism in between workbench and macros.
It would mainly target the stock workbenches coming with FreeCAD core and would make use of the command manager to offer possibility to externally integrate a single command into the existing workbench toolbars and/or menus.

The advantage is that user downloading them (through the addon manager for example) would have it immediately and automatically integrated as a new feature in the FreeCAD environment.
Also the "Command" addon could benefit for several internal mechanisms (eg to be exclusive with other commands, or to tell in which conditions it is enabled or disabled).

What are your thoughts on this ?
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: How about a new "Command" addon type ?

Post by chrisb »

Python was banned from FreeCAD files for security reasons. Would this by such a Command addon come through the backdoor?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
drmacro
Veteran
Posts: 8983
Joined: Sun Mar 02, 2014 4:35 pm

Re: How about a new "Command" addon type ?

Post by drmacro »

Kind of a tangent I guess..but, just had a conversation with a guy who wanted to have fields in a Python script that would handle expressions and reference a spread sheet.

Is that likely a security thing as well?

Or is it already doable?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How about a new "Command" addon type ?

Post by openBrain »

chrisb wrote: Mon Sep 27, 2021 7:07 pm Python was banned from FreeCAD files for security reasons. Would this by such a Command addon come through the backdoor?
I would answer with a totally non-technical reply : that's not better but not worse than workbenches and macros. :D
As existing add-ons, that would act only locally on the PC it's installed on, no code would be embedded in files (as Expressions are).
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: How about a new "Command" addon type ?

Post by alonso_jamm »

There is a way to create commands from macros using Interface_Customization. Then they can be added to any workbench, though the toolbars from the workbenches that come with FreeCAD cannot be modified. In order to add custom macros to the workbenches that come with FreeCAD it is needed to create a new toolbar and then add the macro to the new toolbar.

However, the process of adding a macro into a toolbar can be tedious since it is needed to first create the command for the macro and then add it to the toolbars. Maybe when adding a new macro from the addon manager the macro command could be created automatically using the metadata from the macro. Then the user would only need to add it to the toolbars.
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: How about a new "Command" addon type ?

Post by chrisb »

alonso_jamm wrote: Tue Sep 28, 2021 4:13 pm However, the process of adding a macro into a toolbar can be tedious since it is needed to first create the command for the macro and then add it to the toolbars.
You don't have to create a macro. You can add a command directly to a personal toolbar.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How about a new "Command" addon type ?

Post by openBrain »

alonso_jamm wrote: Tue Sep 28, 2021 4:13 pm There is a way to create commands from macros using Interface_Customization. Then they can be added to any workbench, though the toolbars from the workbenches that come with FreeCAD cannot be modified. In order to add custom macros to the workbenches that come with FreeCAD it is needed to create a new toolbar and then add the macro to the new toolbar.
I know that but AFAIK (it could be possible that I'm just ignoring things) you can only create "macro launcher". You cannot create "Command" -- as in the FreeCAD meaning -- that get all the mechanisms to be context aware. (I know you can create them with Python API, but I'm discussing a user friendly thing).
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How about a new "Command" addon type ?

Post by openBrain »

chrisb wrote: Tue Sep 28, 2021 5:41 pm You don't have to create a macro. You can add a command directly to a personal toolbar.
Do you know if it's possible to do this with a custom command that would eg. be contained in a Python file? Or is it limited to existing commands?
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: How about a new "Command" addon type ?

Post by chrisb »

openBrain wrote: Tue Sep 28, 2021 5:49 pm Do you know if it's possible to do this with a custom command that would eg. be contained in a Python file? Or is it limited to existing commands?
Not sure, but I'm afraid it is not possible.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: How about a new "Command" addon type ?

Post by alonso_jamm »

openBrain wrote: Tue Sep 28, 2021 5:49 pm Do you know if it's possible to do this with a custom command that would eg. be contained in a Python file? Or is it limited to existing commands?
It is almost possible to use a custom command from a single file, but I think you need to add the command from a python module. For example, you could create a module using the namespace structure:

Code: Select all

-CustomCommands/
  |-freecad/
    |-customcommands/
      |-__init__.py
      |-init_gui.py
      |-mycommand.py
Here mycommand.py contains the command, for example the command from the wiki. Including the part at the end:

Code: Select all

FreeCADGui.addCommand('My_Command', MyCommand())
init_gui.py then just needs to include mycommand.py:

Code: Select all

from . import command
Then you can add the command to any toolbar you want, from my example the command would be under the CustomCommands category. It requires some setup, but to add more commands it is only required to include them in the init_gui.py file. Also, this setup and modification of init_gui.py could be automated if the command is installed using the addon manager or a similar tool.
Post Reply