OpenSCAD
Interactive Elixir based CAD Modeling with OpenSCAD
OpenSCAD provides a programatic interface for generating CAD models which can ultimately be 3D printed. While it's syntax makes sense for rendering, it leaves something to be desired when it comes to automating large sets of objects. The language also reads, in my opinion, backwards. I found Elixir's pipe operator to be an elegant way to express these models.
cube(size: 3) ## Draw a 3mm cube, with it's bottom left corner at 0,0,0
|> rotate(x: 90) ## rotate it 90 degrees around the x axis
|> translate(y: 10) ## move it 10 mm along the y axis (depth)
Features
- Models defined in Elixir
- Resuable components can be included as mix dependencies
iex -S mixwill watch for changes in a project's./modelsdirectory, and run those scripts.
Installation
OpenSCAD
You'll need OpenSCAD.
brew cask install openscadOr just download it for your platform here
Adding to your project
Add to your project by putting the following in mix.exs:
def application do
[extra_applications: [:logger, :open_scad]]
end
def deps do
[{:open_scad, "~> 0.1.0"}]
endThis includes the OpenSCAD language and a watcher for filesystem changes.
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/open_scad.
Creating Models
In your projects' ./models directory, create exs scripts. They can output any
number of .scad files.
Your ./lib directory, you can define modules that represent complex, reusable
objects. These are things that you might want to include in other project, which
you can do by including your project as a dependency in that projects' mix file.
Examples
My Keyboards repo is built with this library, and is a full working example.
Language Implementation
The OpenSCAD Language Introduction describes three types of things:
-
Object
Anything that can be rendered, and always ends with a
;. - Action An Object OR a variable assignment.
- Operator Anything that changes an Object. Syntactically, they can operate on any action, but as far as I can tell, have no effect.
My intention with this library is to put the heavy lifting of functions,
variables and programming in general on Elixir, so there will be little
accounting for variable assignment, but it should be possible, in order for us
to set things like $fs in a global context. (see Special
Variables
for more.)