r/OpenPythonSCAD • u/DeepReef11 • Aug 15 '25
How to extend to add more functions?
Let say I want to make nrotx which would be rotx but negative. Is it possible to extend so that it works like rotx?
cube(10).nrotx(2)
r/OpenPythonSCAD • u/DeepReef11 • Aug 15 '25
Let say I want to make nrotx which would be rotx but negative. Is it possible to extend so that it works like rotx?
cube(10).nrotx(2)
r/OpenPythonSCAD • u/gadget3D • Jul 18 '25
Our Ancestor was able to create individually colored faces almost immediately after it got manifold.
No idea, why this feature was not yet accesisble to the user. Lets do it now - add a colors argument to polyhedron and make something nice out of it.
colors must be a list of RGB vectors, and it must match the faces size.

Source code is available here at https://bpa.st/TL5A
Lets keep the concept of Polygon "Generators"
This finally enables us to create colored and textures even with a height map. Look forward to see libraries and complete scenes soon.
r/OpenPythonSCAD • u/WillAdams • Jul 16 '25
given that the Windows version (and others?) now have an internal Python, this becomes something of an issue.
It used to work to e.g., install a library into the "main" Python and then access it from w/in OpenPythonSCAD, but now an installed library cannot be seen from w/in OPS, and attempting to install one using code:
import os, sys
os.system(sys.executable + '-m pip install -user gscrib')doesn't seem to work since the test file responds with:
Parsing design (AST generation)... Running Python 3.12.9 without venv. ERROR: Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'gscrib'
Is anyone else trying to use things other than sys and math (which I believe still work?)
(this is with the new 2025-07-15)
r/OpenPythonSCAD • u/adamoell • May 23 '25
Is there a way to turn off code evaluation as you type, and let it only evaluation when you save (a la "classic" OpenSCAD)? I have suffered a few occasions where some invalid code just crashes PythonSCAD, and I lose a few lines of unsaved code. I've poked around the various settings without luck, but I am very new with PythonSCAD - any guidance would be appreciated! I'm running 2025.04.02 on Kubuntu 24.04.
r/OpenPythonSCAD • u/gadget3D • May 22 '25
Access to all the points makes it easy to decorate any object like so:

```
from openscad import *
fn=20
obj = sphere(20,fn=8) # Sample object
pts, tris = obj.mesh()
for t in tris:
for i in range(len(t)):
i1=t[i-1]
i2=t[i]
if i2 > i1:
obj |= circle(1).path_extrude([pts[i1], pts[i2]])
for pt in pts:
obj |= sphere(2) + pt
obj.show()
```
r/OpenPythonSCAD • u/rebuyer10110 • May 19 '25
On the 5.15 build, nimport() can download py files from github, but it is unable to import modules at runtime.
I have the exact setup as prior on an older build. The only difference is...I am on Windows 11 now instead of Windows 10.
Is this a known issue? I peeked at the github issues, but did not see any new issues.
r/OpenPythonSCAD • u/alanbernstein • Apr 05 '25
It looks like path_extrude supports this, so I would hope other functions that accept a list of points can easily support it as well. But polygon does not seem to.
I can work on adding this if I can get a code pointer.
r/OpenPythonSCAD • u/ehblip • Mar 31 '25
Hey friends,
I have just today discovered PythonSCAD (after yesterday discovering OpenSCAD ;), I love the philosophy of both projects, as I am trying to create fully parametric models all the way to slicing.
I have written this script: https://pastebin.com/eGh68mwN
It works correctly but the exported body names in the 3mf file do not appear to match the keys in the dictionary. Are they supposed to? Bambu Slicer reads them as "OpenSCAD Model". The colors also do not transfer, but I did not actually expect that to work.
Thanks friends, even without this feature this has saved me so much time from trying to do the same thing in traditional CAD.
r/OpenPythonSCAD • u/PurchaseSpecific7699 • Mar 30 '25
Hey everyone,
I’ve got a few general questions regarding PythonSCAD and its integration with OpenSCAD:
Integration status Has PythonSCAD already been fully merged into OpenSCAD and enabled by default? If not, is there any rough ETA for when this is expected?
(Alternatively, is there an option or ongoing effort to merge recent changes from OpenSCAD’s master branch into PythonSCAD, to keep it up to date?)
2. Performance
Are there any known performance drawbacks to using PythonSCAD compared to standard OpenSCAD?
If so, are there best practices or guidelines to help minimize the performance hit?
3. Using Python libraries
Is it possible to import and use external Python libraries within PythonSCAD scripts?
If so, could someone point to a guide or example?
(I saw this asked before but couldn’t quite figure out the current state)
Appreciate any insights. Thanks!
r/OpenPythonSCAD • u/PurchaseSpecific7699 • Mar 19 '25
Hi everyone,
I have a simple question:
OpenSCAD supports passing global variables via the -D option.
Help says:
-D [ --D ] arg var=val -pre-define variablesI tried passing variables in a similar way to PythonSCAD, but it seems the Python script isn’t aware of those variables.
It would be highly appreciated if this could be supported!
Many thanks in advance — I really love this great project! 🙏
r/OpenPythonSCAD • u/MoaiJeff • Mar 19 '25
Having trouble with a simple package import. Read through some other threads and still can't get it to work. import math
Installed: OpenSCAD-silicon-2025-01-30
Had python 3.12 installed, but couldn't import math, appended sys.path, but no luck
Installed python 3.13, and included the path in my sys.path and zshrc file.
Any ideas?
r/OpenPythonSCAD • u/apparle • Mar 16 '25
Have you considered adding a flatpak release for linux distributions? I do see the Appimage but it's somewhat clunky to use -- being able to install PythonSCAD directly from flathub repos will provide great flexibility as well as being able to keep up with new releases.
Also, one of my struggles with OpenSCAD has been an extremely slow release cadence. I do see PythonSCAD moving much faster, but I'm not sure if that's just the latest nightly or there's any active effort to find a reasonably stable snapshot.
r/OpenPythonSCAD • u/WillAdams • Mar 03 '25
I know: https://www.python.org/ftp/python/3.11.5/python-3.11.5-amd64.exe is recommended on the download page --- does it break things to install 3.12?
What would be involved in upgrading to that latter version? I somehow have both 3.11 and 3.12 on one of my computers and I want to simplify down to just one....
If removing 3.12 is a good option, that's fine for me (at least for the nonce)
r/OpenPythonSCAD • u/DisastrousCommon6248 • Feb 28 '25
Hi I am an openscad user wanting to switch to this to this but cant get it to work.
I followed the instructions,
Install Pythonscad - note I installed the one without libraries and didnt remove openscad first
Make a .py test file (I opened using the "Python Button" and type :
from openscad import * | cube().output()
3 Set Preferences to allow Python - there was no box to tick in preferences, is there another way?
Any help appreciated
r/OpenPythonSCAD • u/capilot • Feb 16 '25
In other words can I do something like this:
from OpenSCAD import *
model = difference(cube(5, center=True), sphere(r=2.5))
exportStl(model, open("foo.stl", "w"))or am I always going to be spitting out a "foo.scad" file and then launching OpenSCAD from the command line to render it?
I guess part 2 of the question is: either way, which Python library should I be using? Searching for «python openscad» returned quite a lot of results.
r/OpenPythonSCAD • u/Glad-Studio-9179 • Feb 15 '25
The source build recipe for OpenPythonSCAD is mostly working. It fell over in 3 places, which are fortunately relatively easy to fix.
Solution:
sudo apt install libjpeg-dev` then repeat the cmake commandSolution:
sudo apt install libcurl4-openssl-devSolution:
cd ../submodules/libfive
mkdir build
cd build
cmake ..
make -j4
cd ../../build/submodules
ln -s ../../submodules/libfive/build libfive
cd ..
sudo make installr/OpenPythonSCAD • u/gadget3D • Feb 13 '25
Many new options are possible since the new skin() function which also came with the possibility to placed 2d shapes arbritary in space.
One of this options is faces() functions, which takes a solid as input and returns it faces as arbritary-placed 2d shapes in a python list.
These can further be processed like in this example
Drawing a watch is not difficult in openscad, but in this example the right side faces of the inner cylinder is chosen and used as a baseplate to extude the arrow(outwards)
Many more options are possible. you could also offset or make csg oprations before turning them back to 3D
Since now we cannot only turn 2D shapes into 3D, but also visa verce - any number of times

r/OpenPythonSCAD • u/gadget3D • Dec 16 '24
Today I managed to get PythonSCAD working as interactive python interpreter,
with all PythonSCAD functionality included, see yourself
https://www.youtube.com/watch?v=TymFtcB8K8E
Next task is to head towards Jupyter Notbook, but I am lacking some knowledge.
Who is interested in supporting me ?
r/OpenPythonSCAD • u/WillAdams • Nov 29 '24
I have some OpenSCAD code which uses various trigonometric functions to determine coordinates.
I made some notes on this on the wiki, and managed to work through this at one point I believe, but I'm stymied working up a general approach...
Is there a version of:
import mathwhich works in degrees rather than radians?
r/OpenPythonSCAD • u/gadget3D • Oct 25 '24
As cube() is a fundamental primitive which is needed in almost every design,
it makes sense to get more alignment options there.
Alternatively, now you can also specify a 3 character string to center, which specifies the alignment respect to the axes
-([< means : behind the origin
>]}+ means: in front of the origin
|0_ means: centered in respect to the origin
Also its easy to move the cube with + or - operator and specifying 3d vector on the right hand side of the operator.
r/OpenPythonSCAD • u/gadget3D • Oct 20 '24
There might be situations, where PythonSCAD does not automatically see your installed Python Library.
In that case, just tell PythonSCAD, where to find it.
in cmd terminal i have installed qrcode with ' pip install pyqrcode'
Later, you just need to add the correct python site-packages directory to the path variable. do this by
import sys
sys.path.append("\\path\\to'\\the\\site\\directory")
Below you can find the example from the homepage.

r/OpenPythonSCAD • u/gadget3D • 29d ago
Title: Fourier epicycles as real gears – a parametric drawing machine in PythonSCAD
You've probably seen those videos where a chain of rotating circles draws a horse, a portrait or a signature. The math behind it is the complex Fourier series, and the best interactive explanation I know is Jez Swanson's An Interactive Introduction to Fourier Transforms: https://www.jezzamon.com/fourier/ – you can even draw your own shape there and watch it being rebuilt from circles.
I wondered: can this be built as real geometry? Turns out yes, and PythonSCAD is a perfect fit for it.
Treat the drawing as a complex curve z(t) = x(t) + i·y(t). Its Fourier series is
z(t) = Σ c_k · e^(i·k·t)Every term is an arm of length |c_k| that starts at angle arg(c_k) and rotates k times per revolution. Chain the arms tip to tip and the last tip traces the shape.
The frequencies k are integers – and integer speed ratios are exactly what gears do. Each arm sits on a small planetary stage:
a sun fixed to the arm two levels below (the base for arm 2),
a planet fixed to the new arm, riding at the tip of the arm in between (the carrier).
With carrier speed c, sun speed s and ratio ρ = Z_sun / Z_planet:
direct gear mesh: planet = c + (c − s)·ρ → gives 2×, 3×, …
open belt: planet = c − (c − s)·ρ → gives 0, −1×, −2×, … (negative frequencies are essential for closed shapes!)
The script picks mesh or belt automatically, computes integer tooth counts, aligns the teeth so they really mesh in every pose, and refuses impossible combinations.
My first version had the pen hanging down through the whole stack – straight through the base gear. The fix: in this stack every part lives in its own layer, and the last arm is always the outermost one. So the whole mechanism hangs upside down from a bridge, the last arm is the lowest, and the pen draws downwards onto paper, resting on it by gravity in a sleeve. The motor sits on top of the bridge and drives arm 1 via a pinion. The frame columns are placed outside the computed swept envelope of all parts.
| Shape | K | L | PHI |
|---|---|---|---|
| Heart | -1, -3, 2, -2 | 37.5, 9, 7.5, 7.5 | 90, 270, 270, 270 |
| 3-star, sharp tips | 1, -2, 4, -5 | 36, 18, 9, 5 | 0, 0, 0, 0 |
| 5-star with loops | 1, -4, 6, -9 | 36, 16, 8, 4 | 0, 0, 0, 0 |
| 7-rosette with loops | 1, -6, 8, -13 | 36, 14, 8, 4 | 0, 0, 0, 0 |
The heart is a genuine Fourier approximation: the four largest terms of the classic heart curve.
Rules of thumb for your own designs:
Symmetry: if all k leave the same remainder mod m, the curve has m-fold rotational symmetry (1, −2, 4, −5 → 3-fold).
Sharp tips: a cusp appears where the pen velocity Σ k·L·ei(kθ+φ) vanishes – e.g. 1·36 = 2·18 in the 3-star.
Loops: a high frequency whose k·L comes close to that of the base term makes loops.
Calm shapes: let L fall off roughly like 1/|k| or faster.
Keep gear/belt ratios below ~1:8.
Set K, L, PHI at the top, THETA is the drive angle of the shown pose (nice as an add_parameter slider to crank the machine by hand). The console prints the transmission of every stage and the swept envelope.
# Fourier epicycle drawing machine - assembled demo model for PythonSCAD
#
# Arm i rotates with the absolute angle K[i]*THETA + PHI[i] and has length L[i].
# The pen at the tip of the last arm therefore traces
# z(t) = sum_i L[i] * exp(j*(K[i]*t + PHI[i]))
#
# Stack (mechanism coordinates, built bottom-up, then flipped upside down):
# base plate -> drive layer (drive gear on arm 1 + motor pinion)
# -> arm 1 -> gear layer 1 -> arm 2 -> gear layer 2 -> ... -> arm N
# Every layer only holds parts at its own height; the only part crossing layers
# would be the pen. Since arm N is the outermost layer, the pen side beyond it is
# collision free. The mechanism therefore hangs from a bridge, arm N is lowest,
# and the pen draws downward onto paper (gravity-loaded in a sleeve).
#
# Arm i (i >= 2) is driven by a planetary stage: a "sun" fixed to the body two
# levels up the chain (base for arm 2) and a "planet" fixed to arm i, linked by
# direct gear mesh (planet = c + (c-s)*rho) or by an open belt
# (planet = c - (c-s)*rho), with c = carrier speed, s = sun speed, rho = Zsun/Zplanet.
from openscad import *
import math
from fractions import Fraction
# ---------------- parameters ----------------
K = [1, 2, -1] # absolute frequency of each arm (integer multiples of the drive)
L = [40, 20, 10] # arm lengths = amplitudes [mm]
PHI = [0, 30, 90] # phase of each arm [deg]
THETA = 0 # drive angle of the displayed pose [deg]
T_ARM = 3 # arm plate thickness
T_GEAR = 5 # gear / pulley layer thickness
GAP = 0.5 # vertical play between layers
BASE_T = 4 # bridge plate thickness
HUB_R = 4 # radius of the arm ends
POST_R = 1.5 # axle radius
CLR = 0.3 # radial clearance of rotating parts on their axles
MIN_TEETH = 12 # minimum tooth count of any planetary gear
PULLEY_R = 5 # preferred radius of the planet pulley (belt stages)
BELT_T = 1.2 # belt thickness
DRIVE_ZG = 36 # teeth of the drive gear on arm 1
DRIVE_ZP = 12 # teeth of the motor pinion
DRIVE_M = 1.5 # module of the drive pair
DRIVE_DIR = 0 # direction of the motor seen from the center [deg]
MOTOR_R = 12
MOTOR_H = 25
PEN_CLEAR = 15 # distance from the lowest mechanism part to the paper
SLEEVE_L = 8 # pen guide sleeve below arm N
TABLE_T = 6
PAPER_T = 0.3
COL_R = 4 # frame column radius
MARGIN = 4 # clearance between swept envelope and columns
CURVE_W = 0.6 # half line width of the traced curve
CURVE_STEP = 2 # sampling step of the traced curve [deg]
FN = 48
COLORS = ["red", "dodgerblue", "gold", "limegreen", "orange", "purple"]
# ---------------- helpers ----------------
def polar(r, a):
"""Polar to cartesian, angle in degrees."""
return [r * math.cos(math.radians(a)), r * math.sin(math.radians(a))]
def at(obj, xy, z=0, a=0):
"""Rotate around own z axis by a degrees, then move to xy / height z."""
return obj.rotate([0, 0, a]).translate([xy[0], xy[1], z])
def union_all(objs):
"""Balanced union to keep the CSG tree shallow."""
while len(objs) > 1:
objs = [objs[i] | objs[i + 1] if i + 1 < len(objs) else objs[i]
for i in range(0, len(objs), 2)]
return objs[0]
def hole(r, h):
return cylinder(r=r, h=3 * h, center=True, fn=24)
def gear2d(z, r_pitch):
"""Simple trapezoidal-tooth gear outline, tooth 0 centered on +x."""
m = 2 * r_pitch / z
ra, rr = r_pitch + m, r_pitch - 1.25 * m
p = 360 / z
pts = []
for j in range(z):
for r, f in [(rr, -0.3), (ra, -0.12), (ra, 0.12), (rr, 0.3)]:
pts.append(polar(r, j * p + f * p))
return polygon(pts)
def gear(z, r_pitch, h):
return linear_extrude(gear2d(z, r_pitch), height=h)
def mesh_angle(a_s, beta, zs, zp):
"""Rotation of gear 2 so that it meshes with gear 1 (rotated a_s).
beta = direction from gear 1 center to gear 2 center."""
u = (beta - a_s) * zs / 360
e = (round(u) - u) * 360 / zs # offset of the sun tooth nearest the contact line
return beta + 180 - e * zs / zp - 180 / zp
def pulley(r, h):
"""Plain pulley with an off-center mark so its rotation is visible."""
return cylinder(r=r, h=h, fn=FN) - at(hole(r * 0.15, h), polar(r * 0.6, 0))
# ---------------- kinematics ----------------
N = len(K)
assert len(L) == N and len(PHI) == N, "K, L and PHI need the same length"
kk = [0] + K # body 0 = base (speed 0)
A = [0] + [K[i] * THETA + PHI[i] for i in range(N)] # absolute angle of body j
Pos = [[0, 0]] # Pos[j] = tip of arm j
for i in range(N):
d = polar(L[i], A[i + 1])
Pos.append([Pos[-1][0] + d[0], Pos[-1][1] + d[1]])
reach = [sum(L[:j]) for j in range(N + 1)] # max distance of Pos[j] from center
STAGE_H = T_ARM + T_GEAR + 2 * GAP
Z_DRIVE = BASE_T + GAP # drive layer (mechanism coords)
def z_arm(i): return Z_DRIVE + T_GEAR + GAP + (i - 1) * STAGE_H # bottom of arm i
def z_gear(j): return z_arm(j) + T_ARM + GAP # gear layer below arm j+1
Z_MECH = z_arm(N) + T_ARM + 1 # incl. axle cap at the last joint
def col(j):
return "gray" if j == 0 else COLORS[(j - 1) % len(COLORS)]
def stage(i):
"""Transmission driving arm i (i >= 2): ('mesh'|'belt', rho = Zsun/Zplanet)."""
s, c, k = kk[i - 2], kk[i - 1], kk[i]
if c == s:
raise ValueError(f"arm {i-1} does not rotate relative to its reference")
if k == c:
raise ValueError(f"arm {i} would be rigidly fixed to arm {i-1}")
rho = Fraction(k - c, c - s)
return ("mesh", rho) if rho > 0 else ("belt", -rho)
# ---------------- mechanism (built upright, flipped later) ----------------
mech = [] # (object, color) in mechanism coordinates
envelope = [0] # largest radius swept by any moving or fixed part
def add(obj, color):
mech.append((obj, color))
def sweep(center_reach, r):
envelope[0] = max(envelope[0], center_reach + r)
# drive: gear on arm 1 + motor pinion on the bridge
rd, rpn = DRIVE_M * DRIVE_ZG / 2, DRIVE_M * DRIVE_ZP / 2
p_pin = polar(rd + rpn, DRIVE_DIR)
drive = gear(DRIVE_ZG, rd, T_GEAR) - hole(POST_R + CLR, T_GEAR)
add(at(drive, [0, 0], Z_DRIVE, A[1]), col(1))
add(at(cylinder(r=HUB_R, h=GAP, fn=FN) - hole(POST_R + CLR, GAP), [0, 0], Z_DRIVE + T_GEAR), col(1))
add(at(gear(DRIVE_ZP, rpn, T_GEAR), p_pin, Z_DRIVE, mesh_angle(A[1], DRIVE_DIR, DRIVE_ZG, DRIVE_ZP)), "silver")
add(at(cylinder(r=POST_R, h=Z_DRIVE + MOTOR_H, fn=24), p_pin, -MOTOR_H), "silver")
add(at(cylinder(r=MOTOR_R, h=MOTOR_H - 2, fn=FN), p_pin, -MOTOR_H), "dimgray")
sweep(0, rd + DRIVE_M)
sweep(rd + rpn, rpn + DRIVE_M)
# bridge plate (radius fixed later, stored as placeholder index)
BRIDGE_IDX = len(mech)
add(None, "lightgray")
# arms (hole at the pivot, axle for the next arm fused at the tip)
for i in range(1, N + 1):
a, b = Pos[i - 1], Pos[i]
outline = hull(at(circle(r=HUB_R, fn=FN), a), at(circle(r=HUB_R, fn=FN), b))
plate = linear_extrude(outline, height=T_ARM) - at(hole(POST_R + CLR, T_ARM), a)
add(plate.translate([0, 0, z_arm(i)]), col(i))
sweep(reach[i], HUB_R)
# axles: post at Pos[j] is fixed to body j and carries the sun of the next stage
for j in range(N):
zb = BASE_T if j == 0 else z_arm(j) + T_ARM
zt = z_gear(j + 1) + T_GEAR if j + 1 <= N - 1 else z_arm(j + 1) + T_ARM + 1
add(at(cylinder(r=POST_R, h=zt - zb, fn=24), Pos[j], zb), col(j))
# planetary stages
for i in range(2, N + 1):
j = i - 1 # gear layer below arm i
kind, rho = stage(i)
S, Pc = Pos[i - 2], Pos[i - 1]
dist = L[i - 2]
beta = A[i - 1] # carrier direction (sun -> planet)
z0 = z_gear(j)
if kind == "mesh":
n = max(math.ceil(MIN_TEETH / rho.denominator), math.ceil(MIN_TEETH / rho.numerator))
zp, zs = rho.denominator * n, rho.numerator * n
rs, rp = dist * zs / (zs + zp), dist * zp / (zs + zp)
m = 2 * dist / (zs + zp)
a_s = A[i - 2]
a_p = mesh_angle(a_s, beta, zs, zp)
sun, planet = gear(zs, rs, T_GEAR), gear(zp, rp, T_GEAR)
sweep(reach[i - 2], rs + m)
sweep(reach[i - 1], rp + m)
info = f"gear mesh {zs}:{zp}, module {m:.2f}"
else:
rp = min(PULLEY_R, 0.8 * dist / (1 + float(rho)))
rs = rp * float(rho)
a_s, a_p = A[i - 2], A[i]
sun, planet = pulley(rs, T_GEAR), pulley(rp, T_GEAR)
inner = hull(at(circle(r=rs, fn=FN), S), at(circle(r=rp, fn=FN), Pc))
outer = hull(at(circle(r=rs + BELT_T, fn=FN), S), at(circle(r=rp + BELT_T, fn=FN), Pc))
belt = linear_extrude(outer - inner, height=T_GEAR * 0.6)
add(belt.translate([0, 0, z0 + T_GEAR * 0.2]), "dimgray")
sweep(reach[i - 2], rs + BELT_T)
sweep(reach[i - 1], rp + BELT_T)
info = f"belt, pulleys {rs:.1f}:{rp:.1f} mm (ratio {rho})"
add(at(sun, S, z0, a_s), col(i - 2))
planet = planet - hole(POST_R + CLR, T_GEAR)
add(at(planet, Pc, z0, a_p), col(i))
hub = cylinder(r=min(HUB_R, rp), h=GAP, fn=FN) - hole(POST_R + CLR, GAP)
add(at(hub, Pc, z0 + T_GEAR), col(i))
print(f"arm {i}: k={kk[i]}, sun on body {i-2} (k={kk[i-2]}), carrier k={kk[i-1]} -> {info}")
# frame geometry from the swept envelope
R_COL = envelope[0] + MARGIN + COL_R
R_BRIDGE = R_COL + COL_R + 3
bridge = cylinder(r=R_BRIDGE, h=BASE_T, fn=96) - at(hole(POST_R + CLR, BASE_T), p_pin)
mech[BRIDGE_IDX] = (bridge, "lightgray")
# ---------------- world: flip mechanism, add frame, paper, pen ----------------
Z_PAPER = TABLE_T + PAPER_T
TOP = Z_PAPER + PEN_CLEAR + Z_MECH # world height of mechanism z = 0
def W(z): return TOP - z # mechanism z -> world z
parts = [obj.mirror([0, 0, 1]).translate([0, 0, TOP]).color(c) for obj, c in mech]
# table, paper, columns
side = 2 * (R_BRIDGE + 5)
parts.append(cube([side, side, TABLE_T]).translate([-side / 2, -side / 2, 0]).color("burlywood"))
ps = 2 * (sum(L) + 10)
parts.append(cube([ps, ps, PAPER_T]).translate([-ps / 2, -ps / 2, TABLE_T]).color("white"))
for k in range(4):
p = polar(R_COL, 45 + 90 * k)
parts.append(at(cylinder(r=COL_R, h=W(0) - TABLE_T, fn=24), p, TABLE_T).color("gray"))
# pen: sleeve fixed to arm N, pen resting on the paper by gravity
tip = Pos[N]
z_armN_low = W(z_arm(N) + T_ARM) # lower face of arm N in world coords
z_armN_top = W(z_arm(N))
sleeve = cylinder(r=2.2, h=SLEEVE_L, fn=24) - hole(1.4, SLEEVE_L)
parts.append(at(sleeve, tip, z_armN_low - SLEEVE_L).color(col(N)))
pen = at(cylinder(r1=0.3, r2=1.2, h=2, fn=16), tip, Z_PAPER) \
| at(cylinder(r=1.2, h=z_armN_top - Z_PAPER - 2, fn=16), tip, Z_PAPER + 2)
parts.append(pen.color("black"))
# traced curve on the paper
pts = []
for t in range(0, 360, CURVE_STEP):
x = y = 0
for i in range(N):
d = polar(L[i], K[i] * t + PHI[i])
x, y = x + d[0], y + d[1]
pts.append([x, y])
segs = [hull(at(circle(r=CURVE_W, fn=8), p), at(circle(r=CURVE_W, fn=8), q))
for p, q in zip(pts, pts[1:] + pts[:1])]
parts.append(linear_extrude(union_all(segs), height=0.2).translate([0, 0, Z_PAPER]).color("magenta"))
print(f"swept envelope r = {envelope[0]:.1f} mm, columns at r = {R_COL:.1f} mm, "
f"total height = {TOP + MOTOR_H:.1f} mm")
show(parts)Next steps on my list: printable parts (bearings, belt tooth profiles) and an automatic collision check over the full revolution using PythonSCAD's intersection. Happy to hear ideas – and if you find a nice 4-arm parameter set, post it!
r/OpenPythonSCAD • u/WillAdams • Mar 07 '26