PythonSCAD Cheat Sheet
๐งฑ Primitives
cube([x, y, z])Create a cube with specified dimensions
cube([10, 20, 30]).show()sphere(r)Create a sphere with radius r
sphere(15).show()cylinder(h, r1, r2)Create a cylinder with height h and radii r1 and r2
cylinder(h=20, r1=10, r2=5).show()polyhedron(points)Create a 3D polyhedron with given points and triangles
polyhedron([[0,0], [10,0], [5,10]]).show()square([x, y])Create a 2D square
square([10, 10]).show()circle(r)Create a 2D circle
circle(5).show()polygon(points)Create a 2D polygon with given points
polygon([[0,0], [10,0], [5,10]]).show()spline(points)Create a 2D polygon with given points
spline([[0,0], [10,0], [5,10]],fn=20).show()๐ Transformations
translate(obj, [x, y, z]) # Translate object by x, y, z
rotate(obj, [x, y, z]) # Rotate object by x, y, z degrees
scale(obj, [x, y, z]) # Scale obj by x, y, z factors
mirror([obj, x, y, z]) # Mirror object across the plane defined by x, y, z
right(obj, val) # shift obj by val, alternatively left, front, back, up, down
obj + [x,y,z ] # translate object by displacement
rotx(obj, val) # Rotation in one axis , alternatively roty, rotz
obj * factor # scale obj by factor
๐ Boolean Operations
union(obj1, obj2) # Union of obj1 and obj2, alternatively use obj1 | obj2
difference(obj1, obj2) # Subtract obj2 from obj1, alternatively use obj1 - obj2
intersection(obj1, obj2) # Intersection of obj1 and obj2, alternatively use obj1 & obj2
๐ Extrusions
linear_extrude(shape, height=5) # Extrude 2D shape linearly
rotate_extrude(shape, angle=45) # Extrude 2D shape by rotating it
path_extrude(square(3), path) # Extrude shape along a specified path
๐จ Appearance
๐งฐ Advanced Features
hull()(obj1, obj2) # Create convex hull of obj1 and obj2
minkowski(obj1, obj2) # Minkowski sum of obj1 and obj2
offset(shape, delta) # Offset shape by delta
๐งช Displaying Objects
๐ Python-Specific Gadgets
# Quickly arrange objects
show([ cube(4).right(5*i) for i in range(5) ])
# Modify the mesh
c = cube(5)
pts, tri = c.mesh()
for pt in pts:
if pt[2] > 3 and pt[1] > 3:
pt[2] = pt[2] + 3
polyhedron(pts, tri).show()
show(pillar())
๐ Handles
c = cube([10,10,10r])
c.right_side = translate(roty(c.origin, 90),[10,5,5]) # create handle on the right side of the cube
c |= cylinder(r=1,h=8).align(c.right_side) # Attach a cylinder to the new handle
๐ Special variables
๐๏ธ Customizer
add_parameter(name, default)Add a customizer parameter
width = add_parameter("width", 10)add_parameter(..., range=)Slider with min/max (use range() or tuple)
add_parameter("x", 50, range=range(0, 101))add_parameter(..., options=)Dropdown menu
add_parameter("c", "red", options=["red", "green"])add_parameter(..., group=)Organize into tabs
add_parameter("x", 10, group="Size")add_parameter(..., description=)Add help text
add_parameter("x", 10, description="Width in mm")add_parameter(..., step=)Spinbox with custom step
add_parameter("angle", 45.0, step=0.5)add_parameter(..., max_length=)String max length
add_parameter("name", "hi", max_length=20)