If I understand this MR correctly there might be the option to use Python to write OpenSCAD geometry in the next release. This could be huge!
Obviously refactoring would be a huge task, I don’t see it happening in the short term. I have no idea how much compatibility there will be between the Python and they OpenSCAD code (i.e.) can you make modules in one and call them in the other?
However, if we have Python OpenSCAD as an option this opens up doors for a very bright future:
- Packaging OpenFlexure libraries
- Core OpenFlexure elements (gears, motors, actuator columns, flexure mechanisms, mountings) could all sit in a pip-installable package
- Optics considerations could sit in a pip-installable package
- Microscope/Block Stage/Delta Stage could then use these underlying modules
- Opens the doors for other downstream projects to rely on the libraries
- Hopefully we can package up the rendering/assembly system so it is not Microscope specific.
- Python ecosystem
- We can use more advanced syntax and data structures to help us in so many ways:
- with calculations (we don’t need to do much that is complex… but writing calculations in OpenSCAD is a dark art)
- Using well defined data structures for passing data through the codebase
- No weird separation between module and function code allowing us to not have to write code twice so it can work for calculations or for physical geometry.
- Code robustness can be improved with real linters (SCA2D helps, but is pretty rubbish), with unit tests, coverage reports.
- Standardised doc strings means we can actually generate documentation for how to use the codebase
- We can use more advanced syntax and data structures to help us in so many ways:
- Possible improved integration with other CAD/visualisation
- More control over the underlying code should make it easier to actually define parts and sub-assemblies. This should make it possible to use possible to export individual components from OpenSCAD and then with python assembly information build up a more complex CAD model of these components. This should hopefully allow animations of the assembly.
- Both FreeCAD and CadQuery are Python based. It may be possible to write Python code that defines interfaces like the top of the microscope stage. If this was done in a way that the top stage could be generated in FreeCAD and exported as a STEP, then it could be used for designing add-ons in other CAD packages.
Conclusion
Controlling OpenSCAD fully from Python could be a game changer. But it would take a huge amount of work. Once this is out in the open it would be great to think about how this sort of work could be funded. It would also be great to engage with the OpenSCAD community, however their forum is broken and I can’t handle mailing lists.