ParametricDesignwithOpenSCAD JaySummet jay@summet.com Copyright Jay Summet All Rights Reserved
OpenSCAD OpenSourceparametricdesigntool ExecutablesforWindows,Mac,Linux Freetodistribute,freetouse,cross platform Convertstextualinstructionsinto3Dshapes SupportsConstructiveSolidGeometry(CSG) modeling
ResourceLinks Downloads: http://www.openscad.org UserManual: http://en.wikibooks.org/wiki/openscad_user_manual
Comments C/Java/C++commentingconventions Anytextafteradoubleforward slash(//)onaline isignoredbytheparser. Multi linecommentsarestartedwithaslash star (/*)andendedwithastar slash(*/)
NamedValues a.k.a.variables Anameisassignedavaluewiththeassignment operator(=).canuseexpressionsontheright handsideoftheassignmentoperatortocalculate values. CAUTION!:NamedValuesaresetatcompile time,notruntime!lastassignmenttakes precidence!(butseethe assign statement...)
Example:
VariableAdvice Tokeepyourselfsane: Alwaysmakenewvariables,neverre assignnew valuestooldvariables. Thinkofvariablesas constants or descriptive names insteadof variables.
Vectors Example:dims=[w,d,h]; Usingsquarebrackets,declareavectorofvalues, eitherfromconstants,expressions,ornamed values/variables. Example:dims=[w*2,d+3,17];
Statements REQUIREsemicolonstoend! Ifyouforgetthesemicolontheparserwilltypically displaytheerrorasoccuringatthebeginningof thenextline. Socheckthelinebeforetheerror!
Sphere
Transformations Objectsandentiresub treescanhave transformationsappliedtothemthataffecttheir size,placement,colorandshape. Mostcommonlyused:rotate,translate Alsouseful:mirror,scale,color,hull Advanced:multmatrix,minkowski
Sphere Translated
sub tree Thetranslatecommandworksonasub treethat containschildnodes.bydefault,thesub tree includestheimmediatelyfollowingobject,ended byasemicolon. Ifyouuse{curlybrackets}todeliniatesub trees, youcanincludemorethanonemoduleorchild node.
Sphere&CubeTranslated
Sphere NotTranslated Note the extra semicolon!
CenteringonOrigin Bydefault,whenasphereiscreateditiscentered ontheorigin. However,acubeiscreatedwithitscorneratthe originbydefault. Thisiswhythecubeinthepreviousslideisnot centered withinthesphereaftertheyareboth translatedthesameamount.
Sphere&CubeTranslated
Creatingacenteredcube
SpecialArcControlvariables $fn Normallysettozero(0)toallow$faand$fs totakeeffect.ifsettoanumber,allcirclesare madewithexactly$fnstraightlinefragments. $fa Minimumangleforafragment.Numberof fragments=360/$fa.defaultsto12(i.e.30 fragmentsforafullcircle) $fs Minimumfragmentsize.Defaultsto2.Very smallcircleswillhaveasmallernumberof fragmentsthan$faspecifies.
Justuse$fn $fnistheeasiesttouse Ifyouwantcircles, cylinders,andspherestobesmoother,increase $fn. Thelarger$fnis,thelongercalculationstakeand themorevertices/filesizeyourexportedmodels willhave. Cansetglobally,orpasstospecificshapes individually.
$fnexample
Modules Likefunctions,butcanaffectsub treesthatfollow them,socanbeusedtoimplementcomplex transformationsaswellasobjects. Allowyoutoreusecode. Canacceptparameters. Useacurly bracketstodeliniatethesub treeof codethatisthemodule. Havelocalvariablenames.
VariableScope root/globalscopeisdifferentfromwithinamodule, soyoucanre defineavariablewithinamodule withoutaffectingitsvalueoutsideofthemodule. Reminder:Becausevariablesaresetatcompile timeinsteadofruntime,youcannotre assigna variableinsideofanifsub tree.
HexNutModule
Justuse$fn
MakeSpheres
MakeSpheres
MakeSpheres
MakeSpheres
Iterationviaforloops for(variable=<vector>)<sub tree> variableis assignedtoeachiteminthevectorandthesub treeisexecuted. for(variable=<range>)<sub tree> Range=[<start>:<end>] Range=[<start>:<increment>:<end>] Note:Rangesyntaxusescolons,andtheresulting rangeincludesthestartandendpoints
for Range
for Vector
for(multiplevariables) rangeandvector
ifstatements Syntaxlooksabouthowyouwouldexpect. Conditionallyexecutedsub treebasedupon booleanexpressionwithoptionalelseclause. Comeinusefulifyouwanttohave twodifferentversionsoftheobject(differentbolt patterns,adapterplates,etc..) Differentstyles/shapesbaseduponuserparameters. debug vs regular mode.
if syntax if ( <boolean Expression > ) { <executes on true> } else { <executes on false> }
if example
if example
ConstructiveSolidGeometry(CSG) Consistsofmodelingcomplexpartsasunions, intersections,anddifferencesof(relatively) simplerparts. Thehullandminkowskitransformationsarealso usefulforcreatingcompoundobjects.
Makingahollowbox Makealargecubeforyouroutsidedimensions. Makeasmallercubeforyour inside dimensions. Translatethesmallercubeinsidethelargercube (andhaveitstickoutthetopbyaverysmall amountsuchas0.01) Ithasto pokeout ofthetopjustalittlebitsothat thetopfaceisdefinatelyopen!
TwoCubes
HollowBox
HalfSphere intersection
Morethanonewaytoskinacat
OrderMatersforDifference!
hull
Modifiercharacters Characters(#,!,%,*)prependedtoobjectstomodify howtheyareprocessed. Generallyusedtovisualizewhatishappening,try outalimitedsetofcodewithoutothercode interfearing,etc. Mostusefulisthe#orDebugModifier,thatdraws objectsintransparentpinkforvisualization purposes.
intersection DebugView
OtherModifierCharacters Theothermodifiercharactersactuallyaffecthow youroutputisgenerated. % backgroundmodifier drawsthesub tree/objectwithtransparentgray,butignoresit forallotherrenderingpurposes.! rootmodifier IgnoreeverythingELSEinyour file,andonlyrenderthissub tree! * disablemodifier Disable/ignorethissubtree.
ResourceLinks Downloads: http://www.openscad.org UserManual: http://en.wikibooks.org/wiki/openscad_user_manual