Skip to content

Creating a parametric object that survives restart

Gaël Écorchard edited this page Mar 5, 2021 · 1 revision

I order to have a parametric object survive FreeCAD restart, a few points must be respected. By "surviving", I mean that even after restarting FreeCAD you can change the properties of the parametric object and the shape will adapt accordingly. If you don't do this, you have a parametric object that has dynamic properties when you create it but looses them after and only retains its immutable shape after restart.

  • write the core of your macro in a separate module. For example, for a macro named GreatParametricObject, put this code in the great_parametric_object.py in the great_parametric_object directory alongside your macro with GreatParametricObject being the class creating your object and call from great_parametric_object.great_parametric_object import GreatParametricObject in the FCMacro file, which becomes a thin-wrapper to the core functionality.
  • do not forget to adapt the __Files__ metadata variable accordingly.
  • put other resources into the great_parametric_object directory, e.g. great_parametric_object/resources/user_confirmation_dialog.ui and ``great_parametric_object/resources/confirm_icon.svg. This keeps things clean and tidy. The only icon that should remain at the same hierarchy level of the macro is its icon, in our case GreatParametricObject.svg` (with the same case).
  • wherever possible, try to separate the UI from the rest, so that the core of your macro is callable from other scripts, possibly without GUI.

As of writing, there are two good examples for this in the ParametricObjectCreation directory: GeodesicDome.FCMacro and HoneycombSolid.FCMacro.