I've been using OpenSCAD for ~6 years, and it's my go-to tool for both 2D
and 3D modeling. Recently I've been using OpenSCAD to model organizers for
some of my board games, and beyond a certain point it became irritating to
manually export the STL files. So I started writing makefiles. The manual
gives some suggestions for using makefiles, but I found them to be somewhat
clunky. So I did something that worked for me. I'm sharing it here; maybe
it will work for someone else.
Goals:
Here's what I ended up with:
and
OPENSCAD=/usr/bin/openscad
OPENSCAD_OPTIONS=-DVERBOSE=false
IMAGE_OPTIONS=--imgsize=1024,768 --colorscheme=DeepOcean
SLIC3R=/opt/Slic3r/latest/slic3r
SLIC3R_INI=slic3r.ini
SLIC3R_OPTIONS=--load $(SLIC3R_INI) --print-center 125,105
PREFIX=splendor
PARTS=$(shell grep 'PART == ' $(PREFIX).scad | cut -d'"' -f2)
STL=stl
IMAGE=png
GCODE=gcode
MODELS=$(patsubst %,$(STL)/$(PREFIX)-%.$(STL),$(PARTS))
IMAGES=$(patsubst %,$(IMAGE)/$(PREFIX)-%.$(IMAGE),$(PARTS))
GCODES=$(patsubst %,$(GCODE)/$(PREFIX)-%.$(GCODE),$(PARTS))
all: models gcodes images
directories:
@mkdir -p $(STL) $(IMAGE) $(GCODE)
models: directories $(MODELS)
gcodes: directories $(GCODES)
images: directories $(IMAGES)
clean:
rm -rf $(STL) $(GCODE) $(IMAGE)
$(MODELS) : $(STL)/$(PREFIX)-%.$(STL) : $(PREFIX).scad
$(OPENSCAD) $(OPENSCAD_OPTIONS) -o $@ -DPART="$(subst $(PREFIX)-,,$(subst
.$(STL),,$(@F)))" $<
$(IMAGES) : $(IMAGE)/$(PREFIX)-%.$(IMAGE) : $(PREFIX).scad
$(OPENSCAD) $(OPENSCAD_OPTIONS) -o $@ -DPART="$(subst $(PREFIX)-,,$(subst
.$(IMAGE),,$(@F)))" $(IMAGE_OPTIONS) $<
$(GCODES) : $(GCODE)/%.$(GCODE) : $(STL)/%.$(STL) $(SLIC3R_INI)
$(SLIC3R) -o $@ $(SLIC3R_OPTIONS) $<
When I want to add this Makefile to an existing project, all I usually have
to do is set the PREFIX variable in the Makefile, and then add the switch
block at the bottom of the OpenSCAD source file.
You can find source code examples on GitHub:
https://github.com/wcraigtrader/game-parts/blob/master/splendor/Makefile
https://github.com/wcraigtrader/game-parts/blob/master/splendor/splendor.scad
Feedback is always appreciated.
Please be warned that left tabs are removed (at least from my E-mail client), so the quoted code needs small manual repair.
It looks like a good idea to get the thing from github.
From: Discuss discuss-bounces@lists.openscad.org on behalf of W. Craig Trader craig.trader@gmail.com
Sent: 28 September 2017 02:47:14
To: discuss@lists.openscad.org
Subject: [OpenSCAD] Makefile for building complex models from a single file
I've been using OpenSCAD for ~6 years, and it's my go-to tool for both 2D and 3D modeling. Recently I've been using OpenSCAD to model organizers for some of my board games, and beyond a certain point it became irritating to manually export the STL files. So I started writing makefiles. The manual gives some suggestions for using makefiles, but I found them to be somewhat clunky. So I did something that worked for me. I'm sharing it here; maybe it will work for someone else.
Goals:
Here's what I ended up with:
OPENSCAD=/usr/bin/openscad
OPENSCAD_OPTIONS=-DVERBOSE=false
IMAGE_OPTIONS=--imgsize=1024,768 --colorscheme=DeepOcean
SLIC3R=/opt/Slic3r/latest/slic3r
SLIC3R_INI=slic3r.ini
SLIC3R_OPTIONS=--load $(SLIC3R_INI) --print-center 125,105
PREFIX=splendor
PARTS=$(shell grep 'PART == ' $(PREFIX).scad | cut -d'"' -f2)
STL=stl
IMAGE=png
GCODE=gcode
MODELS=$(patsubst %,$(STL)/$(PREFIX)-%.$(STL),$(PARTS))
IMAGES=$(patsubst %,$(IMAGE)/$(PREFIX)-%.$(IMAGE),$(PARTS))
GCODES=$(patsubst %,$(GCODE)/$(PREFIX)-%.$(GCODE),$(PARTS))
all: models gcodes images
directories:
@mkdir -p $(STL) $(IMAGE) $(GCODE)
models: directories $(MODELS)
gcodes: directories $(GCODES)
images: directories $(IMAGES)
clean:
rm -rf $(STL) $(GCODE) $(IMAGE)
$(MODELS) : $(STL)/$(PREFIX)-%.$(STL) : $(PREFIX).scad
$(OPENSCAD) $(OPENSCAD_OPTIONS) -o $@ -DPART="$(subst $(PREFIX)-,,$(subst .$(STL),,$(@F)))" $<
$(IMAGES) : $(IMAGE)/$(PREFIX)-%.$(IMAGE) : $(PREFIX).scad
$(OPENSCAD) $(OPENSCAD_OPTIONS) -o $@ -DPART="$(subst $(PREFIX)-,,$(subst .$(IMAGE),,$(@F)))" $(IMAGE_OPTIONS) $<
$(GCODES) : $(GCODE)/%.$(GCODE) : $(STL)/%.$(STL) $(SLIC3R_INI)
$(SLIC3R) -o $@ $(SLIC3R_OPTIONS) $<
When I want to add this Makefile to an existing project, all I usually have to do is set the PREFIX variable in the Makefile, and then add the switch block at the bottom of the OpenSCAD source file.
You can find source code examples on GitHub:
https://github.com/wcraigtrader/game-parts/blob/master/splendor/Makefile
https://github.com/wcraigtrader/game-parts/blob/master/splendor/splendor.scad
Feedback is always appreciated.
This is my version of an automatic makefile:
https://github.com/oysteinkrog/thing_spool_stand/blob/master/Makefile
It lets you define your parts as modules in your scad files then
automatically detects them (searches all .scad files) and generates stl
files.
It is also clever in that it will only rebuild parts if any of the dependent
files are modified.
Here is an example:
https://github.com/oysteinkrog/thing_spool_stand/blob/master/spool-stand.scad
The makefile is fully automatic and can just be dropped into any project
without changes.
--
Sent from: http://forum.openscad.org/