50
 Parametric Design with OpenSCAD Jay Summet [email protected] Copyright Jay Summet – All Rights Reserved

Using Opens Cad

Embed Size (px)

Citation preview

  • ParametricDesignwithOpenSCAD

    JaySummet [email protected]

    Copyright Jay Summet All Rights Reserved

  • OpenSCAD

    OpenSourceparametricdesigntool ExecutablesforWindows,Mac,Linux Freetodistribute,freetouse,crossplatform Convertstextualinstructionsinto3Dshapes SupportsConstructiveSolidGeometry(CSG)

    modeling

  • ResourceLinks

    Downloads:http://www.openscad.org

    UserManual:http://en.wikibooks.org/wiki/OpenSCAD_User_Manual

  • Comments

    C/Java/C++commentingconventions Anytextafteradoubleforwardslash(//)onaline

    isignoredbytheparser. Multilinecommentsarestartedwithaslashstar

    (/*)andendedwithastarslash(*/)

  • NamedValues

    a.k.a.Variables Anameisassignedavaluewiththeassignment

    operator(=).Canuseexpressionsontherighthandsideoftheassignmentoperatortocalculatevalues.

    CAUTION!:NamedValuesaresetatcompiletime,NOTRUNTIME!Lastassignmenttakesprecidence!(Butseetheassignstatement...)

  • Example:

  • VariableAdvice

    Tokeepyourselfsane: Alwaysmakenewvariables,neverreassignnew

    valuestooldvariables. Thinkofvariablesasconstantsordescriptive

    namesinsteadofvariables.

  • Vectors

    Example:dims=[w,d,h]; Usingsquarebrackets,declareavectorofvalues,

    eitherfromconstants,expressions,ornamedvalues/variables.

    Example:dims=[w*2,d+3,17];

  • Statements

    REQUIREsemicolonstoend! Ifyouforgetthesemicolontheparserwilltypically

    displaytheerrorasoccuringatthebeginningofthenextline.

    Socheckthelinebeforetheerror!

  • Sphere

  • Transformations

    Objectsandentiresubtreescanhavetransformationsappliedtothemthataffecttheirsize,placement,colorandshape.

    Mostcommonlyused:rotate,translate Alsouseful:mirror,scale,color,hull Advanced:multmatrix,minkowski

  • SphereTranslated

  • subtree

    Thetranslatecommandworksonasubtreethatcontainschildnodes.Bydefault,thesubtreeincludestheimmediatelyfollowingobject,endedbyasemicolon.

    Ifyouuse{curlybrackets}todeliniatesubtrees,youcanincludemorethanonemoduleorchildnode.

  • Sphere&CubeTranslated

  • SphereNotTranslated

    Note the extra semicolon!

  • CenteringonOrigin

    Bydefault,whenasphereiscreateditiscenteredontheorigin.

    However,acubeiscreatedwithitscornerattheoriginbydefault.

    Thisiswhythecubeinthepreviousslideisnotcenteredwithinthesphereaftertheyarebothtranslatedthesameamount.

  • Sphere&CubeTranslated

  • Creatingacenteredcube

  • SpecialArcControlvariables

    $fnNormallysettozero(0)toallow$faand$fstotakeeffect.Ifsettoanumber,allcirclesaremadewithexactly$fnstraightlinefragments.

    $faMinimumangleforafragment.Numberoffragments=360/$fa.Defaultsto12(i.e.30fragmentsforafullcircle)

    $fsMinimumfragmentsize.Defaultsto2.Verysmallcircleswillhaveasmallernumberoffragmentsthan$faspecifies.

  • Justuse$fn

    $fnistheeasiesttouseIfyouwantcircles,cylinders,andspherestobesmoother,increase$fn.

    Thelarger$fnis,thelongercalculationstakeandthemorevertices/filesizeyourexportedmodelswillhave.

    Cansetglobally,orpasstospecificshapesindividually.

  • $fnexample

  • Modules

    Likefunctions,butcanaffectsubtreesthatfollowthem,socanbeusedtoimplementcomplextransformationsaswellasobjects.

    Allowyoutoreusecode. Canacceptparameters. Useacurlybracketstodeliniatethesubtreeof

    codethatisthemodule. Havelocalvariablenames.

  • VariableScope

    root/globalscopeisdifferentfromwithinamodule,soyoucanredefineavariablewithinamodulewithoutaffectingitsvalueoutsideofthemodule.

    Reminder:Becausevariablesaresetatcompiletimeinsteadofruntime,youcannotreassignavariableinsideofanifsubtree.

  • HexNutModule

  • Justuse$fn

  • MakeSpheres

  • MakeSpheres

  • MakeSpheres

  • MakeSpheres

  • Iterationviaforloops

    for(variable=)variableisassignedtoeachiteminthevectorandthesubtreeisexecuted.

    for(variable=) Range=[:] Range=[::] Note:Rangesyntaxusescolons,andtheresulting

    rangeincludesthestartandendpoints

  • forRange

  • forVector

  • for(multiplevariables)rangeandvector

  • ifstatements

    Syntaxlooksabouthowyouwouldexpect. Conditionallyexecutedsubtreebasedupon

    booleanexpressionwithoptionalelseclause. Comeinusefulifyouwanttohave

    twodifferentversionsoftheobject(differentboltpatterns,adapterplates,etc..)

    Differentstyles/shapesbaseduponuserparameters. debugvsregularmode.

  • ifsyntaxif ( ){ } else { }

  • ifexample

  • ifexample

  • ConstructiveSolidGeometry(CSG)

    Consistsofmodelingcomplexpartsasunions,intersections,anddifferencesof(relatively)simplerparts.

    Thehullandminkowskitransformationsarealsousefulforcreatingcompoundobjects.

  • Makingahollowbox

    Makealargecubeforyouroutsidedimensions. Makeasmallercubeforyourinsidedimensions. Translatethesmallercubeinsidethelargercube

    (andhaveitstickoutthetopbyaverysmallamountsuchas0.01)

    Ithastopokeoutofthetopjustalittlebitsothatthetopfaceisdefinatelyopen!

  • TwoCubes

  • HollowBox

  • HalfSphereintersection

  • Morethanonewaytoskinacat

  • OrderMatersforDifference!

  • hull

  • Modifiercharacters

    Characters(#,!,%,*)prependedtoobjectstomodifyhowtheyareprocessed.

    Generallyusedtovisualizewhatishappening,tryoutalimitedsetofcodewithoutothercodeinterfearing,etc.

    Mostusefulisthe#orDebugModifier,thatdrawsobjectsintransparentpinkforvisualizationpurposes.

  • intersectionDebugView

  • OtherModifierCharacters

    Theothermodifiercharactersactuallyaffecthowyouroutputisgenerated.

    %backgroundmodifierdrawsthesubtree/objectwithtransparentgray,butignoresitforallotherrenderingpurposes.

    !rootmodifierIgnoreeverythingELSEinyourfile,andonlyrenderthissubtree!

    *disablemodifierDisable/ignorethissubtree.

  • ResourceLinks

    Downloads:http://www.openscad.org

    UserManual:http://en.wikibooks.org/wiki/OpenSCAD_User_Manual

    Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50