Syntax Reference
The following is a cheat sheet style reference for all operators in DSLCAD. Please refer to the examples folder for even more reference on how to build parts.
Cheat Sheet
Getting Started
cube();draw a 1x1x1 cubesquare(x=10, y=5) -> extrude(z=2);extrude a 2D shape into 3Dcube() -> translate(z=2) -> difference(sphere());move a shape and cut a sphere out of it- run
dslcad ./part.dsto writepart.3mf, ordslcad ./part.ds --previewto edit live
Coordinates are in millimetres.
Syntax
// texta comment to the end of the linevar name = value;declare a variable called name that stores valuename = value;reassign an existing variablevar name;declare a parameter, set from the CLI with--argument name=valuevalue;draw the value; each top-level value is a separate part123,1.5numbers;true/falsebooleans;"text"strings (escapes\n,\t,",\)b(name=a)pass the value ofaas the named argumentnameof functionbb(a)passaas the first argument ofb(positional arguments are matched in order)a ->name b()pipeainto the named argumentnameof functionba -> b()pipeainto the first argument ofba.baccess propertybofa(for examplepoint.x,shape.center,shape.volume)list[0]get an item of a list (the index is zero-based){ ... }a scope;func { ... }a function that takes its own argumentsif a: b() else: c()branch on conditiona(theelsebranch is required)- statements may end at a newline instead of a semicolon, like JavaScript automatic semicolon insertion
Collections and Loops
[1, 2, 3]make a list with three numbersmap LIST as NAME: OPERATIONloop over every entry in LIST, collecting the resultsreduce LIST as NAME1,NAME2: OPERATIONcombine every item in LISTreduce LIST from BASE as NAME1,NAME2: OPERATIONcombine every item in LIST starting from BASE
Resources
./part.ds(name=a)run another script as if it were a function@lib/part.ds(name=a)run a shared script from the nearestmodulesdirectory (searched upward from the current file)./model.stl()import an STL mesh as a 3D shape./drawing.svg()import an SVG drawing as a 2D line or plane./font.ttf(message="hi")import text from a TrueType/OpenType font as a 2D plane./data.ini()import an INI file as an object of text values
Resource arguments can be any expression, so ./font.ttf(message=name) works with a variable.
Operators
a + baddition; concatenates text when both sides are texta - bsubtractiona * bmultiplicationa / bdivisiona % bmoduloa ^ bpower-anegate a number
Logic
a < bless than (numbers only)a <= bless than or equal (numbers only)a == bequal (numbers only)a != bnot equal (numbers only)a > bgreater than (numbers only)a >= bgreater than or equal (numbers only)a and blogical anda or blogical ornot alogical not
Properties
point.x,point.y,point.zcoordinates of a point2d_value.centercenter of a 2D object3d_value.centercenter of a 3D object3d_value.volumevolume of a 3D object
Signature Notation
name(type)required argument of the given typename=[type]optional argument (values in the description are the defaults)name=*argument of any type...any number of additional named argumentsline|planeaccepts either type
Math
pi()constant pirad_to_deg(radians=number)convert radians to degreesdeg_to_rad(degrees=number)convert degrees to radianssin(degrees=number)sine of an angle given in degreessin(radians=number)sine of an angle given in radianscos(degrees=number)cosine of an angle given in degreescos(radians=number)cosine of an angle given in radianstan(degrees=number)tangent of an angle given in degreestan(radians=number)tangent of an angle given in radiansround(number=number)round to the nearest whole numberceil(number=number)round up to a whole numberfloor(number=number)round down to a whole numbersqrt(number=number)square root of a number
2D
point(x=[number], y=[number], z=[number])create a point in 2D or 3D space (x, y and z default to 0)line(start=point, end=point)create a line between two pointssquare(x=[number], y=[number])create a rectangle (x and y default to 1)circle(radius=[number])create a circle (radius defaults to 0.5)arc(start=point, center=point, end=point)create an arcing line between three pointsunion(left=line|plane, right=line|plane)combine two 2D shapesface(parts=list)make a closed face from a list of points, lines and arcstranslate(shape=line|plane, x=[number], y=[number], z=[number])move a 2D shaperotate(shape=line|plane, angle=[number])rotate a 2D shape around the z axis by angle in degreesrotate(shape=line|plane, x=[number], y=[number], z=[number])rotate a 2D shape around the x, y and z axes by degreesscale(shape=line|plane, scale=number)scale a 2D shapenormalize(shape=line|plane)scale a 2D shape so its largest side is 1 unit longcenter(shape=line|plane, x=[bool], y=[bool], z=[bool])center a 2D shape on the given axes (each axis defaults to true; pass false to leave it in place)offset(shape=plane, distance=number)expand a closed 2D shape outward by distancesimplify(shape=line|plane, tolerance=[number])remove detail from a line or plane so it stays within tolerance of the originalthicken(shape=line, distance=[number], x=[number], y=[number], z=[number])turn a line into a face by thickening it
3D
extrude(shape=plane, x=[number], y=[number], z=[number])extrude a face into a 3D shaperevolve(shape=plane, x=[number], y=[number], z=[number])revolve a face around the x, y or z axis (the value is the angle in degrees)bend(shape=shape, x=[number], y=[number], z=[number])bend a shape around the x, y and z axes (each value is an angle in degrees)simplify(shape=shape)merge same-domain faces and edges of a shape to reduce its complexitycube(x=[number], y=[number], z=[number])create a cube or box (x, y and z default to 1)sphere(radius=[number])create a sphere (radius defaults to 0.5)cylinder(radius=[number], height=[number])create a cylinder (radius defaults to 0.5, height to 1)union(left=shape, right=shape)combine two shapeschamfer(shape=shape, radius=number)chamfer edgesfillet(shape=shape, radius=number)fillet edgesdifference(left=shape, right=shape)cut one shape out of anotherintersect(left=shape, right=shape)intersection between two shapestranslate(shape=shape, x=[number], y=[number], z=[number])move a shaperotate(shape=shape, x=[number], y=[number], z=[number])rotate a shape around the x, y and z axes by degreesscale(shape=shape, scale=number)scale a shape uniformlyscale(shape=shape, x=[number], y=[number], z=[number])scale a shape independently on the x, y and z axesnormalize(shape=shape)scale a shape so its largest side is 1 unit longcenter(shape=shape, x=[bool], y=[bool], z=[bool])center a shape on the given axes (each axis defaults to true; pass false to leave it in place)slice(left=shape, right=line|plane)cut a 2D cross-section out of a shapeslice(left=shape, right=shape)cut one shape out of another
Lists
length(list=list)get the length of a listrange(start=[number], end=number)create a list of whole numbers from start (default 0) up to but not including end
Text
string(item=*)convert a number, boolean or text to textformat(message=text, ...)format text using {my_arg} style formattingformatln(message=text, ...)format text with newlineerror(message=text)generate an error