Skip to content

Extrusions

Extrusion operations convert 2D shapes (or Python functions) into 3D solids.

linear_extrude

Extrude a 2D shape (or Python function) along the Z axis.

Syntax:

linear_extrude(obj, height=1, convexity=1, origin=None, scale=None,
               center=False, slices=1, segments=0, twist=None)
obj.linear_extrude(height=1, ...)

Parameters:

Parameter Type Default Description
obj 2D solid or function — Shape to extrude, or a Python function f(h) -> [[x,y], ...]
height number or [x,y,z] 1 Extrusion height (number for Z-axis, vector for arbitrary direction)
convexity int 1 Convexity for rendering
origin [x, y] None Origin point for twist/scale operations
scale [x, y] None Scale factor at the top of the extrusion
center bool False Center vertically
slices int 1 Number of intermediate slices
segments int 0 Number of segments for twist
twist number or function None Twist angle in degrees, or a Python function f(h) -> angle
fn, fa, fs — Curve discretization parameters

PythonSCAD extensions:

The obj parameter can be a Python function that receives a height value and returns a list of 2D points defining the cross-section at that height:

from pythonscad import *
from math import *

def xsection(h):
    v = 5 + sin(h)
    return [[-v, -v], [v, -v], [v, v], [-v, v]]

linear_extrude(xsection, height=10, slices=20).show()

The twist parameter can also be a Python function:

from pythonscad import *

square(5, center=True).linear_extrude(height=20, twist=90, slices=50).show()

Examples:

from pythonscad import *

circle(5).linear_extrude(height=10).show()

circle(5).linear_extrude(height=10, twist=90, slices=50).show()

circle(5).linear_extrude(height=10, scale=[2, 0.5]).show()

OpenSCAD reference: linear_extrude


loft

Create a cross-section function that transitions between two 2D shapes. Pass the result to linear_extrude() to build the lofted solid.

Syntax:

loft(shape1, shape2, height, n=20, rot=0)

Parameters:

Parameter Type Default Description
shape1 2D solid — Cross-section at height 0
shape2 2D solid — Cross-section at height
height number — Height over which to interpolate; must be non-zero
n int 20 Minimum number of additional angular samples
rot number 0 Rotation of the second profile in degrees

loft() samples each outline radially from the origin and returns a function f(h) -> [[x, y], ...]. The input shapes should therefore surround the origin and have one unambiguous boundary intersection in each direction (for example, centered convex shapes).

Example:

from pythonscad import *

profile = loft(
    square(10, center=True),
    circle(r=3, fn=24),
    height=20,
    n=24,
    rot=45,
)
linear_extrude(profile, height=20, slices=20).show()

rotate_extrude

Extrude a 2D shape by rotating it around the Z axis.

Syntax:

rotate_extrude(obj, convexity=1, scale=1.0, angle=360, twist=None,
               origin=None, offset=None, v=None, method="centered")
obj.rotate_extrude(...)

Parameters:

Parameter Type Default Description
obj 2D solid or function — Shape to extrude, or a Python function f(angle) -> [[x,y], ...]
convexity int 1 Convexity for rendering
scale float 1.0 Scale factor at the end of rotation
angle float 360 Rotation angle in degrees
twist number or function None Twist angle or function
origin [x, y] None Origin for twist/scale
offset [x, y] None Offset for the profile
v [x, y, z] None Translation per revolution for helix (PythonSCAD extension)
method string "centered" Helix pitch method: "centered" (use mid-X of the profile) or "linear"
fn, fa, fs — Curve discretization parameters

PythonSCAD extensions:

The obj parameter can be a Python function that receives an angle and returns a 2D cross-section:

from pythonscad import *
from math import *

def xsection(h):
    v = 2 * sin(4 * pi * h)
    return [[10+v, -v], [15-v, -v], [15-v, 5+v], [10+v, 5+v]]

rotate_extrude(xsection, fn=50).show()

The v parameter creates a helix by translating the profile along a vector per revolution:

from pythonscad import *

circle(3).right(10).rotate_extrude(v=[0, 0, 20], angle=600).show()

Examples:

from pythonscad import *

# Simple torus
circle(3).right(10).rotate_extrude().show()

# Partial rotation
square([2, 3]).right(5).rotate_extrude(angle=270).show()

OpenSCAD reference: rotate_extrude


path_extrude

Extrude a 2D shape along an arbitrary 3D path. A 4th value in each path vertex specifies the corner radius at that point.

Syntax:

path_extrude(obj, path, xdir=None, convexity=1, origin=None,
             scale=None, twist=None, closed=False,
             allow_intersect=False, fn=-1, fa=-1, fs=-1)
obj.path_extrude(path, ...)

Parameters:

Parameter Type Default Description
obj 2D solid or function — Cross-section shape or Python function
path list of [x,y,z] or [x,y,z,r] — 3D path points; optional 4th element is corner radius
xdir [x, y, z] [1, 0, 0] X-direction vector for profile orientation
convexity int 1 Convexity for rendering
origin [x, y] None Origin for the profile
scale [x, y] None Scale factor at the end
twist number or function None Twist angle or function
closed bool False Close the path into a loop
allow_intersect bool False When False, warn if consecutive extruded profiles appear to collide (cross-section vertices behind the previous profile plane). This is not a full path self-intersection test
fn, fa, fs float -1 Curve discretization

Examples:

from pythonscad import *

# Extrude a square along a path with rounded corners
p = path_extrude(
    square(1),
    [[0,0,0], [0,0,10,3], [10,0,10,3], [10,10,10]]
)
p.show()

skin

Create a surface that smoothly connects multiple 2D profiles placed in 3D space. This is essentially morphing between shapes.

Syntax:

skin(obj1, obj2, ..., convexity=1, align_angle=None, segments=None, interpolate=None)

Parameters:

Parameter Type Default Description
obj1, obj2, ... 2D solids — Profiles to skin between (positioned in 3D space)
convexity int 1 Convexity for rendering
align_angle float None Angle to align profiles
segments int None Number of interpolation segments
interpolate float None Interpolation factor

Examples:

from pythonscad import *

# Morph a square into a circle
a = square(4, center=True).roty(40)
b = circle(r=2, fn=20).rotx(40).up(10)
skin(a, b).show()