Script to create a proper standalone document with some automation on it

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
onekk
Veteran
Posts: 6215
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Script to create a proper standalone document with some automation on it

Post by onekk »

Hello, I'm experimenting a little with some scripting.

My new frontier is to make a standalone FCStd file that is autonomous from the creation script, but, as the document is complex and rely on many expressions stored in a spreadsheet "Dimensions" that do the hard work of automating things and with some documentation in "Documentation" as a bonus to add instructions on what to do with parameters.

This is a working example as it is a "side result" of some jobs I have recently done (more complex things could be obtained).

20221208-automation.py
(9.59 KiB) Downloaded 26 times
automation.FCStd
(27.11 KiB) Downloaded 27 times
Note the very different dimension of files, the script and the produced file.

Hoping it will be useful for someone.

I'm interested in some suggestion and "constructive critics".

Regards

Carlo D.
Last edited by onekk on Sat Dec 10, 2022 9:59 pm, edited 2 times in total.
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/
edwilliams16
Veteran
Posts: 3184
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Script to create a proper standalone document with some automation on it

Post by edwilliams16 »

Looks to be a simpler template than having to learn about QT i/o. I personally have less interest in tweaking the UI than working on algorithms.

@onekk
User avatar
onekk
Veteran
Posts: 6215
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Script to create a proper standalone document with some automation on it

Post by onekk »

edwilliams16 wrote: Fri Dec 09, 2022 12:42 am Looks to be a simpler template than having to learn about QT i/o. I personally have less interest in tweaking the UI than working on algorithms.

@onekk
So you prefer this approach over as example a QtDialog taylor made to input data?

It is less powerful, but probably with some more research and maybe some "Feature Request" about improving Spreadsheet it could lead to something interesting.

Script could do a very good job on filling spreadsheet cells, I have done more complex things as you could leverage for loop and such things to automate repetitive tasks, thing of filling proper tuning as example to make a shelve or a drawers chest with different drawers front heights.

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/
User avatar
onekk
Veteran
Posts: 6215
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Script to create a proper standalone document with some automation on it

Post by onekk »

I have a minor glitch:

If I color a part and then modify a dimension using "Dimensions" spreadsheet, solids are "recalculated" but:

- Shapecolor is not "honoured" and the solids are the "usual grey" (204, 204, 204) in decimal.
- but Shapecolor is correcly set to the desired color, only color is not "re-applied" to the recalculated shape.

I have solved it with this little Macro:

Code: Select all

import FreeCAD
import FreeCADGui

doc = FreeCAD.ActiveDocument

for obj in doc.Objects:
    if obj.TypeId in ('Part::Box', 'Part::Cut'):
        color = obj.ViewObject.ShapeColor
        obj.ViewObject.ShapeColor = color

But is a suboptimal solution, as the file is not anymore "standalone"

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/
Post Reply