Check out my first novel, midnight's simulacra!

OpenSCAD: Difference between revisions

From dankwiki
No edit summary
Line 2: Line 2:


==Basic shapes==
==Basic shapes==
* Square (rectangle), circle, polygon
* <tt>square</tt> (rectangle), <tt>circle</tt>, <tt>polygon</tt>
* Cube (rectangular prism), sphere, cylinder, polyhedron
* <tt>cube</tt> (rectangular prism), <tt>sphere</tt>, <tt>cylinder</tt>, <tt>polyhedron</tt>


<tt>circle</tt> and <tt>cylinder</tt> are approximated using the <tt>fn</tt> system variable. Low values of <tt>fn</tt> can be used to generate regular polygons. A cylinder can have different radii at its top and bottom. A right pentagonal frustrum, for instance, can be generated with <tt>cylinder</tt> using <tt>fn=5</tt>.
<tt>circle</tt> and <tt>cylinder</tt> are approximated using the <tt>fn</tt> system variable. Low values of <tt>fn</tt> can be used to generate regular polygons. A cylinder can have different radii at its top and bottom. A right pentagonal frustrum, for instance, can be generated with <tt>cylinder</tt> using <tt>fn=5</tt>.

Revision as of 07:39, 2 October 2024

OpenSCAD is a declarative 3d modeling program. Objects are defined in terms of basic 2D and 3D shapes, and a set of operators is provided to manipulate these objects. It can generate STL files from the command line.

Basic shapes

  • square (rectangle), circle, polygon
  • cube (rectangular prism), sphere, cylinder, polyhedron

circle and cylinder are approximated using the fn system variable. Low values of fn can be used to generate regular polygons. A cylinder can have different radii at its top and bottom. A right pentagonal frustrum, for instance, can be generated with cylinder using fn=5.

A 2D shape can be converted into a 3D one using linear_extrude or rotate_extrude().

use vs include

A SCAD file can include other SCAD files with either the include or use keywords. include statements are replaced with the body of the included file (any includes or uses within the file are expanded). use only lifts modules and functions, and only affects the current file (i.e. recursive uses do not escape beyond the file that uses them).

It's useful to have a file draw its various modules, so that running it at the top level generates examples etc. Such a file can be imported with use, and these examples won't be drawn.

These cannot be used within a module or function.