Howto: Using the scad-clj
OpenSCAD DSL on the CLI
This DSL domain specific language was used by adereth to make the dactyl keyboard. This howto is based on Adereth's blog post.
OpenSCAD becomes insane after awhile and what it needs most is lisp, because everything needs lisp.
Install leiningen
What is leiningen?
There are a lot of ways to do this.
- check out the leiningen website
- macos:
brew install leiningen
On 2017/12/28 the project page says:
be sure you get version 2.x
Check your version in a shell
$ lein -v
Leiningen 2.8.1 on Java 1.8.0_144 Java HotSpot(TM) 64-Bit Server VM
Get scad-clj
Available on github: https://github.com/farrellm/scad-clj
Quickstart!
Based on Adereth's 2014/3/19 Post: 3d printing with Clojure
Save this code as example.clj
in the git repository scad-clj
that you just cloned:
;; import scad-clj objects or something
(ns scad-demo.core
(:use [scad-clj.scad])
(:use [scad-clj.model]))
;; make something called primitives
(def primitives (sphere 50))
;; export primitives to scad
(spit "example.scad" (write-scad primitives))
- In a shell,
cd
into the scad-clj project directory:cd scad-clj
- Run the
example.clj
file:$ lein repl < example.clj
- Start the OpenSCAD program
- Navigate to and open the generated example.scad in OpenSCAD
- You can now make changes to
example.clj
as you wish, recompile them, and reload the file in OpenSCAD. - As an example, try changing the sphere to size 50 in
example.clj
- run the repl command
- your OpenSCAD instance should auto reload
- If this setting is not already chosen it is at (see the menu - TODO, add exact
file->location_name
) - If not, choose
file->reload
orCMD+r
on a mac.
- Todo: run from your own project directory,
not scad-clj
.- Otherwise it's messy and hard to keep stuff under source control.
- Use adereth's
dactyl
project as a template (avoid users needing to know much about clojure/lein/OpenSCAD before starting)