Add an option to incorporate Macro in the CAD file
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 45
- Joined: Thu Sep 15, 2022 8:54 pm
Add an option to incorporate Macro in the CAD file
Hello,
I'd like to suggest and new feature for FreeCAD that might improve the life for new user or for the ones that will use Freecad for one specif purpose and like convenience.
Would it be possible to incorporate the macro script into the CAD file *.FCStd?
Currently, macros are manage as a separate file and rely on the Software not on the model, if you change your computer, you need to set up all macro again. Offering and option to incorporate the macro in the file itself will give user some convenience as Microsoft Excel Or Libre Office Calc do with incorporate macro, and this can improve UX.
The current Macro as library can remain as it is, and maybe just offer a second option to built-in macro in the model.
I'd like to suggest and new feature for FreeCAD that might improve the life for new user or for the ones that will use Freecad for one specif purpose and like convenience.
Would it be possible to incorporate the macro script into the CAD file *.FCStd?
Currently, macros are manage as a separate file and rely on the Software not on the model, if you change your computer, you need to set up all macro again. Offering and option to incorporate the macro in the file itself will give user some convenience as Microsoft Excel Or Libre Office Calc do with incorporate macro, and this can improve UX.
The current Macro as library can remain as it is, and maybe just offer a second option to built-in macro in the model.
Re: Add an option to incorporate Macro in the CAD file
You may save python code to Text_document (Menu > Tools > Add text document) and run it:
eval(FreeCAD.activeDocument().getObject("Text_document").Text)
eval(FreeCAD.activeDocument().getObject("Text_document").Text)
Re: Add an option to incorporate Macro in the CAD file
Have you taken in account the "risk of malware" when you permit to execute a code from a "zipped container" like a FCStd file is?
From what I know this has been discussed and reject in the past to avoid this risk.
It could be handy, but you could even use a taylor made Wb and use ScriptedObjects to achieve what you want in a "relatively easy" way.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Add an option to incorporate Macro in the CAD file
the whole point of embedding the macro is to be able to run in stock FreeCAD elsewhere without having to setup addons/macros. IMO this could be a handy feature as long as the macro can't run automatically. Perhaps a context menu item in the text object mentioned above "Open as macro" which would open the the macro editor with that text, with this the user will be forced to at least have a passing look at the macro he's about to run.
Re: Add an option to incorporate Macro in the CAD file
I know this and I agree that this could be handy.adrianinsaval wrote: ↑Tue Sep 27, 2022 3:40 pm ...
the whole point of embedding the macro is to be able to run in stock FreeCAD elsewhere without having to setup addons/macros. IMO this could be a handy feature as long as the macro can't run automatically.
If I remember well sometime ago I have had a discussion with some developers about an easy way to extend FCStd format, as example having the possibility to populate some styles, stored in a sqlite3 database or even a way to use directly the sqlite3 db to store "binary blobs" like images or macro and and the proposition was rejected due to this risk of "malware", but this was done some time ago when @yorick was integrating "Annotations Styles", so I could remember wrong.
I admit that prohibit the "automatic execution" is a "measure of security" but how much users confirm blindly a "warning message" without reading it?
I could make a file that do the equivalent of "format C:" in a python macro, and if the user has installed FC with "administrator privileges" like some people are suggesting even in this forum ....
Probably something like a warning that some "addon module" is required to "use the file" should be a "decent compromise", as addons are checked or at least if an addon is making something harmful it could be "blacklisted".
But probably here is not the correct place to discuss these things, more on "developers" forum.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Posts: 45
- Joined: Thu Sep 15, 2022 8:54 pm
Re: Add an option to incorporate Macro in the CAD file
Thank for the feedbacks. I hope you can take a good decision in order to implement the tool in the best way.
Re: Add an option to incorporate Macro in the CAD file
A sufficiently convenient process could be:
- distribute the model together with the macros, e.g. in a zipped folder
- unzip the folder somwhere else
- run the macro from the menu
This is already possible, but it is unconvenient, that the configured macro path changes. I would like to see the possibility implemented to call a single macro and leave the path as configured in the preferences. This would not open a security hole, as it is not just confirming one of these never read messages.
- distribute the model together with the macros, e.g. in a zipped folder
- unzip the folder somwhere else
- run the macro from the menu
This is already possible, but it is unconvenient, that the configured macro path changes. I would like to see the possibility implemented to call a single macro and leave the path as configured in the preferences. This would not open a security hole, as it is not just confirming one of these never read messages.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Add an option to incorporate Macro in the CAD file
This works:
Code: Select all
eval(compile(FreeCAD.activeDocument().getObject("Text_document").Text, "<string>", "exec"))