parametric design with openscad...openscad open source parametric design tool executables for...
TRANSCRIPT
![Page 1: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/1.jpg)
Parametric Design with OpenSCAD
Jay Summet [email protected]
Copyright Jay Summet – All Rights Reserved
![Page 2: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/2.jpg)
OpenSCAD
Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions into 3D shapes Supports Constructive Solid Geometry (CSG)
modeling
![Page 3: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/3.jpg)
Resource Links
Downloads:http://www.openscad.org
User Manual: http://en.wikibooks.org/wiki/OpenSCAD_User_Manual
![Page 4: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/4.jpg)
![Page 5: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/5.jpg)
Comments
C/Java/C++ commenting conventions Any text after a double forwardslash ( // ) on a line
is ignored by the parser. Multiline comments are started with a slashstar
( /* ) and ended with a starslash ( */ )
![Page 6: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/6.jpg)
Named Values
a.k.a. Variables A name is assigned a value with the assignment
operator ( = ). Can use expressions on the right hand side of the assignment operator to calculate values.
CAUTION! : Named Values are set at compile time, NOT RUN TIME! Last assignment takes precidence! ( But see the ”assign” statement...)
![Page 7: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/7.jpg)
Example:
![Page 8: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/8.jpg)
Variable Advice
To keep yourself sane: Always make new variables, never reassign new
values to old variables. Think of variables as ”constants” or ”descriptive
names” instead of ”variables”.
![Page 9: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/9.jpg)
Vectors
Example: dims = [w,d,h]; Using square brackets, declare a vector of values,
either from constants, expressions, or named values/variables.
Example: dims = [w*2, d+3, 17];
![Page 10: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/10.jpg)
Statements
REQUIRE semicolons to end! If you forget the semicolon the parser will typically
display the error as occuring at the beginning of the next line.
So check the line before the error!
![Page 11: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/11.jpg)
Sphere
![Page 12: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/12.jpg)
Transformations
Objects and entire subtrees can have transformations applied to them that affect their size, placement, color and shape.
Most commonly used: rotate, translate Also useful: mirror, scale, color, hull Advanced: multmatrix, minkowski
![Page 13: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/13.jpg)
Sphere Translated
![Page 14: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/14.jpg)
subtree
The translate command works on a subtree that contains child nodes. By default, the subtree includes the immediately following object, ended by a semicolon.
If you use {curly brackets} to deliniate subtrees, you can include more than one module or child node.
![Page 15: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/15.jpg)
Sphere & Cube Translated
![Page 16: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/16.jpg)
Sphere Not Translated
Note the extra semicolon!
![Page 17: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/17.jpg)
Centering on Origin
By default, when a sphere is created it is centered on the origin.
However, a cube is created with its corner at the origin by default.
This is why the cube in the previous slide is not ”centered” within the sphere after they are both translated the same amount.
![Page 18: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/18.jpg)
Sphere & Cube Translated
![Page 19: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/19.jpg)
Creating a centered cube
![Page 20: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/20.jpg)
Special Arc Control variables
$fn – Normally set to zero (0) to allow $fa and $fs to take effect. If set to a number, all circles are made with exactly $fn straight line fragments.
$fa – Minimum angle for a fragment. Number of fragments = 360 / $fa. Defaults to 12 (i.e. 30 fragments for a full circle)
$fs – Minimum fragment size. Defaults to 2. Very small circles will have a smaller number of fragments than $fa specifies.
![Page 21: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/21.jpg)
Just use $fn
$fn is the easiest to use – If you want circles, cylinders, and spheres to be smoother, increase $fn.
The larger $fn is, the longer calculations take and the more vertices / file size your exported models will have.
Can set globally, or pass to specific shapes individually.
![Page 22: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/22.jpg)
$fn example
![Page 23: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/23.jpg)
Modules
Like functions, but can affect subtrees that follow them, so can be used to implement complex transformations as well as objects.
Allow you to reuse code. Can accept parameters. Use a curlybrackets to deliniate the subtree of
code that is the module. Have local variable names.
![Page 24: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/24.jpg)
Variable Scope
root/global scope is different from within a module, so you can redefine a variable within a module without affecting its value outside of the module.
Reminder: Because variables are set at compile time instead of run time, you can not reassign a variable inside of an if subtree.
![Page 25: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/25.jpg)
HexNut Module
![Page 26: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/26.jpg)
Just use $fn
![Page 27: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/27.jpg)
Make Spheres
![Page 28: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/28.jpg)
Make Spheres
![Page 29: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/29.jpg)
Make Spheres
![Page 30: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/30.jpg)
Make Spheres
![Page 31: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/31.jpg)
Iteration via for loops
for ( variable = <vector> ) <subtree> variable is assigned to each item in the vector and the subtree is executed.
for (variable = <range> ) <subtree> Range = [ <start> : < end> ] Range = [ <start> : <increment> : <end> ] Note: Range syntax uses colons, and the resulting
range includes the start and end points
![Page 32: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/32.jpg)
for Range
![Page 33: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/33.jpg)
for Vector
![Page 34: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/34.jpg)
for (multiple variables) range and vector
![Page 35: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/35.jpg)
if statements
Syntax looks about how you would expect. Conditionally executed subtree based upon
boolean expression with optional else clause. Come in useful if you want to have
two different versions of the object (different bolt patterns, adapter plates, etc..)
Different styles/shapes based upon user parameters. ”debug” vs ”regular” mode.
![Page 36: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/36.jpg)
if syntaxif ( <boolean Expression > ){ <executes on true>} else { <executes on false>}
![Page 37: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/37.jpg)
if example
![Page 38: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/38.jpg)
if example
![Page 39: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/39.jpg)
Constructive Solid Geometry (CSG)
Consists of modeling complex parts as unions, intersections, and differences of (relatively) simpler parts.
The hull and minkowski transformations are also useful for creating compound objects.
![Page 40: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/40.jpg)
Making a hollow box
Make a large cube for your outside dimensions. Make a smaller cube for your ”inside” dimensions. Translate the smaller cube inside the larger cube
(and have it stick out the top by a very small amount such as 0.01) –
It has to ”poke out” of the top just a little bit so that the top face is definately open!
![Page 41: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/41.jpg)
Two Cubes
![Page 42: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/42.jpg)
Hollow Box
![Page 43: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/43.jpg)
Half Sphere intersection
![Page 44: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/44.jpg)
More than one way to skin a cat
![Page 45: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/45.jpg)
Order Maters for Difference!
![Page 46: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/46.jpg)
hull
![Page 47: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/47.jpg)
Modifier characters
Characters (#,!,%,*) prepended to objects to modify how they are processed.
Generally used to visualize what is happening, try out a limited set of code without other code interfearing, etc.
Most useful is the # or Debug Modifier, that draws objects in transparent pink for visualization purposes.
![Page 48: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/48.jpg)
intersection – Debug View
![Page 49: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/49.jpg)
Other Modifier Characters
The other modifier characters actually affect how your output is generated.
% background modifier draws the subtree/object with transparent gray, but ignores it for all other rendering purposes.
! root modifier – Ignore everything ELSE in your file, and only render this subtree!
* disable modifier – Disable/ignore this subtree.
![Page 50: Parametric Design with OpenSCAD...OpenSCAD Open Source parametric design tool Executables for Windows, Mac, Linux Free to distribute, free to use, crossplatform Converts textual instructions](https://reader035.vdocuments.site/reader035/viewer/2022062403/5fd0d8c2862a444afe4baf62/html5/thumbnails/50.jpg)
Resource Links
Downloads:http://www.openscad.org
User Manual: http://en.wikibooks.org/wiki/OpenSCAD_User_Manual