SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.11k stars 173 forks source link

Adds default import paths as in OpenSCAD documentation #110

Closed n-e-g closed 4 years ago

n-e-g commented 5 years ago

Adds default search paths as stated in OpenSCAD documentation. This allows including standard libraries as well as user libraries stored in dedicated SCAD directories.

etjones commented 5 years ago

This is really great! I didn't realize OpenSCAD had added default library directories. With the code you've added, is there any difference in between the OpenSCAD use('path/to/library.scad') and the SolidPython use('path/to/library.scad')? I'm trying to think what instructions we should add to the README documentation to describe how imports work now that you've added this feature.

n-e-g commented 5 years ago

Well, the whole process is described here: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries This page describes search path order which I reflected in the commit.

Example: when you put MCAD library in ~/.local/share/OpenSCAD/libraries/MCAD then in OpenSCAD: use('MCAD/shapes.scad') and in SolidPython: use('MCAD/shapes.scad') both will work in the same way.

Absolute paths works without any expansion.

etjones commented 4 years ago

Wow, I really dropped the ball on this one. I just pushed a replacement for this functionality and published it to PyPI as v1.0.2. I generalized the behavior a little from what's in your PR in order to work with the import_scad() namespaced import function, but everything should now work as you intended. So use('MCAD/shapes.scad') works, but so does mcad = solid.import_scad('MCAD'), and the mcad namespace then contains namespaces for each of the modules in MCAD. Thanks for doing to footwork on this last year, and I'm sorry I took so long incorporating it. Cheers!