Open sadr0b0t opened 6 years ago
export OPENSCADPATH=scad_modules
then run openscad from same terminal or add this line to ~/.profile file
For details on use, include and library dirs see here: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Use_and_Include https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
for example, we have 2 modules installed in project/scad_modules dir project/scad_modules/pd-gears/pd-gears.scad project/scad_modules/gearbox/gearbox.scad
example scad design: project/gearbox-demo.scad
Example design uses gearbox module and gearbox module depends on pd-gears module.
Use gearbox module inside gearbox-demo.scad like this:
use <gearbox/gearbox.scad>
Also inside gearbox module use pd-gears dependance module in the same way:
project/scad_modules/gearbox/gearbox.scad
use <pd-gears/pd-gears.scad>
This would also work
Looks like we can't replace node_modules with scad_modules with default npm without patching it
https://docs.npmjs.com/files/folders https://stackoverflow.com/questions/21818701/use-a-custom-directory-name-instead-of-node-modules-when-installing-with-npm#21818724
So, will have to install openscad modules to node_modules as well
export OPENSCADPATH=node_modules
add to either ~/.profile (will not work with ~/.profile) ~/.bashrc or ~/.bash_aliases:
alias spm='npm --registry=https://registry.openscad-modules.tk'
check on new login
spm search fractal
spm adduser
Username: sadr0b0t
Password:
Email: (this IS public) xxx@yandex.ru
Logged in as sadr0b0t on https://registry.openscad-modules.tk/.
to generate test package before publishing to registry
spm pack
Then check out pd-gears-2.0.0.tgz
Publish to registry:
spm publish
- pd-gears@2.0.0
check in new project dir:
spm install pd-gears
export OPENSCADPATH=node_modules
only works when start OpenSCAD from console, unfortunately
when start from console, then check help > info (import works):
OPENSCADPATH: node_modules OpenSCAD library path: /home/user/projects/gearbox/node_modules
when open .scad file from file manager (import does NOT work):
OPENSCADPATH: node_modules OpenSCAD library path: /home/user/node_modules
so, it does not use OPENSCADPATH variablle dynamically, it just takes OPENSCADPATH at start and puts it together with current dir (in case, if the path is relative, most likely). When open .scad file from file manager current dir by some reason is set to $HOME
submitted feature request here https://github.com/openscad/openscad/issues/2377
And another issue here
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
In the case of a library file itself having use <...> or include <...> the directory of the library .scad file is the 'calling' file, i.e. when looking for libraries within a library, it does not check the directory of the top level .scad file.
So, even if we include gearbox.scad like "gearbox/gearbox.scad" from "node_modules" relatively to current project, and then gearbox.scad would also include pd-gears.scad with relative path like "pd-gears/pd-gears.scad" or even like "node_modues/pd-gears/pd-gears.scad", it won't see it, because it will not go down to the root module and would look pd-gears some where near node_modules/gearbox/ or in global libraries.
pull request to handle all above: https://github.com/openscad/openscad/pull/2384
Hi,
I was running in the same issues, especially because of NPMs flat dependency feature. However,
as far as I have looked up the issue, setting OPENSCADPATH=node_modules
on startup helps to fix this. I haven't yet updated the documentation, because was running out of time.
For example (extended by MCAD):
We have the following dependencies (in this example MCAD is used with the same version for all modules, if not, NPM would installs it nested and hence the problem itself would not be present) and at least the following files/libraries are present:
node_modules/gearbox/gearbox.scad -> depends node_modules/gears/pd_gears.scad, node_modules/MCAD/nuts_and_bolts.scad
node_modules/gears/pd_gears.scad -> depends node_modules/MCAD/gears.scad
node_modules/MCAD/gears.scad node_modules/MCAD/nuts_and_bolts.scad
NPM will recognize that MCAD is used by multiple modules of the whole project and installs it flat (on top level of node_modules) folder. So, setting OPENSCAD_PATH=node_modules (root node_modules folder of project) and everything should be fine (so far :) ).
So, setting OPENSCAD_PATH=node_modules (root node_modules folder of project) and everything should be fine (so far :) ).
Unfortunately, this only works when start OpenSCAD from console from project dir. Will not work when double-click on .scad file in file manager.
That's because currently OpenSCAD always simply creates absolute paths from relative paths in OPENSCADPATH
add_librarydir(fs::absolute(fs::path(boost::copy_range<std::string>(*it))).string());
See this comment: https://github.com/sadr0b0t/pd-gears/issues/1#issuecomment-381360778
I have opened issue https://github.com/openscad/openscad/issues/2377 and created patch with pull requst https://github.com/openscad/openscad/pull/2384
with more details on this, please, take a look
offtopic side-note for openscad build instructions - to change install dir before build do:
qmake openscad.pro PREFIX='/home/user/apps/openscad'
make install
Convert project to modulle compatible with OpenSCAD-Modules OpenSCAD module manager experimental project (based on NPM) and publish to openscad-modules registry.
https://github.com/RobertFach/Openscad-Modules http://forum.openscad.org/A-Package-Manager-for-OpenSCAD-td23465.html
example project https://github.com/RobertFach/openscad-fractals/blob/master/package.json
For reference - another experimental module manager project for OpenSCAD based on Ruby gems https://github.com/lostapathy/scad_bundler#draft-conventions