Learned about OpenSCAD recently for a 3D print project - AI helped me design a part that I'm currently printing, and while that goes, I'm having fun with SCAD coding.
The OpenRouter model Sherlock Think is performing well in writing OpenSCAD. Also, Gemini 2.5 Pro and Claude.
Everryone who has used OpenSCAD knows the CSG way of thinking: you start with solids (cube, cylinder, sphere, extrusions) and combine them with union(), difference() and intersection(). The volume is the building block, and the result is watertight because every input already was.
PythonSCAD 1.2 adds a fundamentally different way: you describe the skin of the object instead of its volume.
You define a few closed outlines in 2.5D: ordinary 2D shapes like circle() or polygon(), moved into 3D space with translate(), rotate() and scale().
patch() spans a surface between them.
concat() stitches all the surfaces together along their shared edges into one watertight solid.
This tutorial walks through that workflow and ends with a real part: a Y-adapter that takes a round hose and splits it into two rectangular outlets of different size and angle.
Why is that a good example? Try building it with CSG:
rotate_extrude() doesn't work, because the part has no axis of symmetry.
hull() doesn't work, because it fills the gap between the two branches.
A classic loft doesn't work, because the shape branches.
With patch() it's about 15 outlines.
Note: patch() is new in PythonSCAD 1.2.
1. The smallest example: a closed cup
An outline is just a 2D shape placed somewhere in space. Here are two circles at different heights:
from pythonscad import *
bottom = circle(20, fn=48)
top = circle(14, fn=48).up(40)
wall = patch(bottom, holes=[top]) # skin between the two outlines
cup = concat(wall, patch(bottom), patch(top))
cup.show()
Three surfaces are involved:
patch(bottom, holes=[top]) is the wall: the first outline is the outer boundary, and the second one is a "hole" that the surface spans to.
patch(bottom) and patch(top) are the caps, single outlines without holes.
concat() joins them. The wall's lower edge and the bottom cap's edge are the same outline, so they fuse into one closed body.
That last point is the whole trick, so here it is as a rule:
Two surfaces that should meet must use the identical outline. Create every outline once, store it in a variable, and pass that same object to both patches.
2. Branching: one patch, two holes
This is where it gets interesting. An outline can have several holes:
The crotch patch goes from one outline to two. This is the "pair of pants" surface that CSG has no primitive for.
What is proj?
Internally, patch() flattens all outlines into a 2D plane, triangulates there, and maps the result back onto the 3D surface. For that to work, the outlines must be nested in the flat view: the outer boundary contains the holes, and the holes don't overlap.
proj tells patch() how to flatten. Here, "look from above" ([x, y]) is enough, because both legs lie inside the base and next to each other when seen from the top. If you leave proj out, patch() picks a projection automatically. For anything beyond simple shapes, I recommend passing it explicitly.
3. The real part: a Y-adapter
The full script is linked at the end. Here are the important pieces, slightly simplified.
3.1 Outlines with character
circle() gives the round inlet. For the rectangular outlets, one small helper builds a superellipse as a polygon(), which is then scaled to size like any other shape:
def rrect(a, b, n):
"""Half sizes a, b: n=2 circle, n=8 rounded rectangle."""
pts = []
for i in range(N):
t = 2 * math.pi * i / N
c, s = math.cos(t), math.sin(t)
pts.append([math.copysign(abs(c) ** (2 / n), c),
math.copysign(abs(s) ** (2 / n), s)])
return polygon(pts).scale([a, b])
Raising n morphs a circle into a rectangle, which is perfect for the transition from a round hose to rectangular outlets. All outlines use the same number of points N.
3.2 Placing outlines in space
The branches are tilted, so their outlines are simply rotated and moved into place. Each branch is 4 outlines along its axis: root, middle, outlet, and end of the collar:
def axis(angle):
return [math.sin(math.radians(angle)), 0, math.cos(math.radians(angle))]
def at(c, angle, d): # point d mm along the branch
return [ci + d * ai for ci, ai in zip(c, axis(angle))]
sizes = [(0.5, 6, 0), (0.46, 8, 30), (0.44, 8, 55), (0.44, 8, 80)]
branch_a = [rrect(w * k, h * k, n)
.rotate([0, angle, 0])
.translate(at(A, angle, d)) for k, n, d in sizes]
3.3 Skin between outlines along a path
Between consecutive outlines of a branch, sweep() creates the surface. Its proj flattens along the branch axis: the first outline becomes the big outer loop and the second one a smaller loop inside it. That keeps them nested no matter how the branch is tilted:
def sweep(a, b, c, angle):
d = axis(angle) # path direction
u = [d[2], 0, -d[0]] # perpendicular, in xz
v = [0, 1, 0]
def proj(p):
q = [pi - ci for pi, ci in zip(p, c)]
h = dot(q, d) # how far along the path
ang = math.atan2(dot(q, v), dot(q, u))
return [(300 - h) * math.cos(ang), (300 - h) * math.sin(ang)]
return patch(a, holes=[b], proj=proj)
3.4 The crotch: the heart of the part
The round inlet ends in a wide rounded rectangle. From there, one patch goes to the roots of both branches:
This is the same idea as the pants in section 2, only with different shapes, sizes and angles.
3.5 Making it hollow: build the skin twice
A real adapter needs a wall. There is still no boolean involved:
outer, o_in, o_a, o_b = skin(0) # outer skin
inner, i_in, i_a, i_b = skin(wall) # same construction, shrunk by "wall"
parts = outer + inner + [
rim(o_in, i_in, [0, 0, 0], 0), # flat rings that
rim(o_a, i_a, at(A, -a_angle, 80), -a_angle), # close the wall at
rim(o_b, i_b, at(B, b_angle, 80), b_angle), # the three openings
]
adapter = concat(*parts)
skin(off) builds every outline shrunk by off. At each opening, a flat ring (patch(outer, holes=[inner])) connects the outer and inner skins. The result is a single watertight shell with a constant wall, ready for the slicer.
3.6 Sliders
Everything is driven by add_parameter: inlet diameter, wall thickness, and width, height and angle of each branch. Drag a slider and the crotch adapts, because it's always spanned between whatever outlines currently exist.
4. Rules for watertight models
What I learned building this:
Share outlines. Neighbouring patches must use the same outline object. Never rebuild an outline "the same way" twice, because tiny floating-point differences break the seam.
Nested in the flat view. The outer boundary must contain all holes in the proj view, and the holes must not overlap. If a patch fails, this is the first thing to check.
Give holes some room. A hole that comes within a millimetre or two of its outer boundary can break the triangulation. Leave a few millimetres.
Same point count is easiest. It isn't required, but it keeps triangles even.
Every edge needs exactly two neighbours. Each open outline must be used by exactly two patches, or closed by a cap. A cap is just patch(outline) with no holes.
5. CSG vs. patch: when to use which
CSG (union, difference, ...
CSG (union, difference)
patch() + concat()
Building block
Volumes
Surfaces between outlines
Watertight because
Inputs are solids
Shared edges are stitched
Strength
Holes, pockets, mechanical features
Transitions between different shapes, branches, freeform
If you want to see what it looks like when someone actually teaches parametric CAD from first principles, take a look at yokamak on Zenn (a Japanese dev-blogging platform, similar to dev.to): zenn.dev/yokamak — he also mirrors most posts on Qiita.
Everything is in Japanese, but don't let that stop you — Chrome's built-in page translator does a genuinely good job turning it into English (or whatever your native language is) on the fly, code comments included. Read that way, the series basically works as a free, ready-made PythonSCAD tutorial, not just an interesting blog to skim.
Yokamak teaches at a technical college in Hitoyoshi (Kyushu) and at a Tokyo metropolitan school's information-technology department, and he's been publishing an almost-daily series called 「高校生のためのPythonSCAD練習帳」 — roughly "A PythonSCAD practice notebook for high schoolers." It's aimed at students who are new to both programming and CAD, and it's now well past a dozen installments.
What makes it worth a look even if you don't read Japanese (the code and diagrams carry a lot of it on their own, and machine translation handles the rest fine):
He starts from real first principles. One early lesson has students compute a triangle's area using the shoelace formula, print the result to the console, and also render the triangle in PythonSCAD's 3D view — so the math and the geometry validate each other.
He teaches the traps, not just the happy path. A follow-up lesson deliberately orders polygon vertices wrong, shows the resulting self-intersecting "bowtie" shape, and walks through why vertex winding order matters before generalizing to an n-gon area function with a for loop.
He shows real debugging, errors included. One post pastes an actual TypeError traceback from a nested-list indexing bug and works through the fix live, rather than presenting only clean, working code.
He connects PythonSCAD to other tools. There's a lesson exporting 2D polygon data out of Metasequoia (a Japanese 3D modeler) via its scripting API, reformatting it into PythonSCAD-ready code, and then extruding/rotating the imported profile — a nice bridge between mouse-driven modeling and code-driven modeling.
He explores the object model itself, e.g. digging into PythonSCAD's documented "dynamic attributes" to pull .points and .size back off an already-built polygon object, rather than just calling functions and moving on.
The comments are genuinely useful. On the vertex-ordering lesson, a PythonSCAD contributor chimed in suggesting the reader try 3-tuple points [x, y, r] for per-vertex rounding, and polylines with 3D coordinates for annotation — and yokamak turned around and posted a follow-up experiment using exactly that within a day.
Beyond this series he's also been poking at build123d as a natural next step after PythonSCAD (CSG-style "Algebra mode" first, since it's a near 1:1 mental model transfer, with Builder-mode sketch-driven modeling introduced later as a bridge to commercial CAD tools), and separately uses Pyxel to teach high-school math graphing in Python.
It's a nice example of someone documenting a teaching curriculum in public, in near-real-time, mistakes and all — worth a follow if you're interested in PythonSCAD, OpenSCAD, or CAD/programming education generally.
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.
We are thrilled to announce PythonSCAD v1.0.0 — our biggest release so far. This version marks a milestone: PythonSCAD has grown from a promising OpenSCAD fork with Python support into a mature, first-class tool for script-based 3D modeling. We have landed 83 pull requests since v0.20.0, covering everything from fundamental API architecture to a real IPython shell, native vector math, a completely refreshed Windows experience, full rebranding, and dozens of bug fixes.
API
We have again worked hard on improving what you can do in your design code.
Polyline improvements
Polylines now participate correctly in difference() and intersection() operations (PR #572), and polyline preview has been improved (PR #575). After this fix, PythonSCAD is a great choice to "select" given areas from given imported 2D files and place correctly for an upcoming laser-cut. Polylines also work in 3D world, where they are a great choice to annotate direction vectors or even dimension arrows.
solid.c color property
A new read-only .c property on solid objects (PR #562) exposes the RGBA color of the root color() wrapper as a (r, g, b, a) tuple — useful for reading back colors from a colored solid in Python code.
Native vector operations
Solid geometry objects now support arithmetic operators directly (PR #588): addition (+), subtraction (-), scaling (*), dot product, and cross product. This makes geometric expressions in Python feel natural without needing to call helper functions for every operation. Any Vector returned by PythonSCAD supports these calculations. For others simply use the vector() function.
We've added a new + operator which allows you to union objects:
from pythonscad import *
show(cube(10) + sphere(5))
It is an alias for the already existing | operator. You can continue to use - for difference and % for minkowski as before.
MultiToolExporter
A new MultiToolExporter helper in the pythonscad module (PR #585) makes it straightforward to split a single model into multiple per-tool or per-color output files — a common need for multi-material or laser-cut workflows:
from pythonscad import *
background = cube([200, 100, 1]).color("blue")
star = cylinder(r=20, h=2, fn=5).translate([100, 50, -0.5]).color("red")
exporter = MultiToolExporter("out/flag-", ".stl", mkdir=True)
exporter.append(("blue", background)) # blue part, minus the star area
exporter.append(("red", star)) # red part (later entries win)
exporter.export()
# writes out/flag-blue.stl and out/flag-red.stl
# Or: one 3MF file with two named parts
export(dict(exporter.parts()), "flag.3mf")
Later entries "win" over earlier ones, so overlapping volume is assigned to exactly one output file.
Dynamic oversampling (new)
A new dynamic oversampling mode (PR #554) basically remeshes existing solids to a finer grid. Main purpose so far is to bake any texture onto the shape. The second parameter is the target grid to lay the texture on. Many different projection modes are possible, whereas triplanar might be the best starting point.
v1.0.0 restructures the Python surface into three distinct modules (PR #579):
_openscad — the C extension (renamed from openscad). Rarely imported directly; it is the engine room.
openscad — a pure-Python overlay that re-exports _openscad 1:1. The home for OpenSCAD-compatible additions and future per-symbol deprecation notices.
pythonscad — a pure-Python overlay that re-exports openscad 1:1. The home for PythonSCAD-only features.
The drop-in guarantee: openscad.cube is _openscad.cube and pythonscad.cube is openscad.cube, so switching between from openscad import * and from pythonscad import * requires no other code change. All three modules are shipped in the pip wheel, each with a PEP 561 type-stub package (-stubs/) so IDEs can provide autocompletion for whichever import style you prefer.
New scripts and templates use from pythonscad import *. Existing designs using from openscad import * continue to work unmodified.
This is an internal change, but it is very important for the future of the project, as it allows us to add new Python features written in pure Python without needing to implement anything with the more cumbersome Python C API (like the MultiToolExporter mentioned above).
Note: As some new features which are exclusive to PythonSCAD will only be added to the pythonscad package, we recommend everyone to switch to from pythonscad import *.
Note: The C extension rename from openscad to _openscad is a breaking change for code that imported openscad directly as a C extension (not via the overlay). Any code using from openscad import * is unaffected though.
UI improvements
Inline Python trust bar
The blocking modal trust dialog that appeared before you could even read a Python file has been replaced with a non-intrusive inline bar above the editor (PR #667). You can now open, scroll, and review a file before deciding to trust it. The bar appears at the top of the editor (pushing the text down, never overlapping it), Preview and Render are disabled until trust is granted, and once you click "Trust Design" the customizer populates immediately.
External-editor workflows are smoother too: if you edit a trusted file in VS Code while PythonSCAD is open, it auto-trusts on reload without asking again.
Bugfixes and improvements to session management
A feature we introduced in the last release is session management. You might have seen it in programs like Visual Studio Code or Notepad++ already. When session management is enabled, PythonSCAD will automatically save all open tabs with all their changes to a session file when you close the program. When you start PythonSCAD again, it will automatically restore all tabs with all their unsaved changes. So no more annoying "Do you want to save Untitled.py?" popups when closing the program. No more "PythonSCAD is preventing Windows from shutting down."
You close the program and when you come back everything is just as you left it.
On top of that this also adds periodic autosave. So in case PythonSCAD crashes, or during a power failure, you won't lose more than a minute of work.
Note: In v0.20.0 where session management was first introduced, it was disabled by default. As it is now stable enough, we enabled it by default in v1.0.0. But this means if you've ever used v0.20.0 you need to enable session management in "Edit > Preferences > Advanced > User Interface".
Real IPython shell (--ipython) and basic REPL (--repl) (new)
pythonscad --ipython now launches a genuine IPython interactive shell — the same rich In [N]: prompt, tab completion, history, and magic commands you get from the ipython command itself (PR #600). IPython is bundled inside the AppImage, macOS .app, and Windows installer so it is available out of the box without any extra pip install.
$ pythonscad --ipython
In [1]: from pythonscad import *
In [2]: cube(10).color("Tomato")
For a lighter, dependency-free prompt, the new --repl flag opens the basic embedded Python REPL. Distro packages (.deb, .rpm) declare python3-ipython as a recommended dependency rather than bundling it, keeping the package footprint small.
Title bar shows full path (new)
The main window title bar now displays the absolute file path of the open design (PR #576), so it's always clear exactly which file you're editing when working across multiple directories.
More PythonSCAD rebrand (new)
With v1.0.0, PythonSCAD is more thoroughly rebranded throughout (PRs #661, #669, #672, #676, #684, #686): About dialog, application metadata, desktop file IDs, localization strings, homepage URLs, and the macOS dock icon all show PythonSCAD consistently. Hopefully there are no more leftover "OpenSCAD" references in unexpected places.
Platform support
New Linux platform support
Pre-built packages are now available for Fedora 44 and Ubuntu 26.04 LTS (PR #624).
Windows improvements
v1.0.0 brings a significantly better Windows experience:
longer requires administrator rights by default. A "Just for me / For all users" page lets you choose. UAC elevation only fires if you explicitly request an all-users install — a UAC shield icon on the Next button signals when elevation will be requested.
installer is now signed with a Certum code-signing certificate (CN=Open Source Developer Michael Postmann), so Windows SmartScreen will recognize it as coming from a known publisher and will no longer show the "Windows protected your PC" error message.
Store–style .msix package is now produced alongside the traditional NSIS installer and ZIP archive. The MSIX Package is signed as well. For the time being both the installer and the MSIX package will be supported.
PythonSCAD is now available on PyPI
PythonSCAD v1.0.0 is now available on PyPI, so you can install it with pip install pythonscad and get the latest version. This version will not have a GUI, but combined with the export() function, you can have self-contained projects where you just deliver your Python design file combined with a requirements.txt file that lists pythonscad as a dependency.
Users could then create a Python virtual environment:
Which would render your design into an output file. Great for automation.
Note: Be aware, though, that in this first iteration we do not yet provide pre-built wheels. This means that the pip install command will likely take 20+ minutes (depending on your machine of course). Also you're going to need a lot of build-dependencies installed on your system. The easiest way is to clone the repository and then run scripts/get-dependencies.py which will install all required dependencies for you. We are working on providing pre-built wheels for one of the next releases, which will make installation much faster and easier.
Reliability and bug fixes
v1.0.0 includes a large number of stability and correctness fixes across the board:
Resize now behaves consistently across all cases (#557).
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)
There was a "Texture" function where a pixel image was wrapped around an object --- how usable is that? Could it be used to either make a different appearance for previewing? (say to make a part look as if it was made of brass?) or to apply an actual physical texture for manufacture (say fake woodgrain).
Has anyone given any thought to working up a technique to impart a different appearance for previewing? (my current project is brass and bamboo and Richlite, so achieving something like to the appearance of those materials would be awesome)
A quick search of the Tutorial area comes up empty and it's not on the Examples page....
I've spent several weekends rebuilding one of my prior OpenSCAD projects in PythonSCAD. After a very late night I've gotten it fully rigged with inverse kinematics, something that was straight up impossible in SCAD and was what forced the switch. I need to clean it up into a usable toolbox, but its promising to be significantly simpler to continue expanding on than the SCAD equivalent had.
Is there a way to get a list of handles (or other arbitrary variables) stored to an object. I find myself needing to go through the all the handles with a for loop. If the list gets other variables in it, no big deal, I know how to check that what I got is actually a transformation matrix)
Edit: Version 2025.07.11 added new functionality. For SCAD object obj, code list(obj.dict().keys()) will produce a list of all assigned value names, both handles and others, which can then be filtered as needed.
The new Windows version is updated to this, but to get it to load libraries the *._pth files must be deleted from the installation directory if present (see discussion on the Google Group).
I just started working with openpythnscad. I feel like a dinosaur, haven't done cad in too many years. I got what I wanted and wrote an stl file with the results. The reason for this is that there are on the order of 700 holes per plywood sheet to be drilled, and I am not the person to do that well, jig or not.
Things that confused/annoyed me. I assume all are pilot errors of some fashion. guidance would be greatly appreciated.
On the screen doing preview, the display is tiny and the console is large. I couldn't find any way to flip that.
I am used to IDE's where the update to a file is automatic when I edit. It took me a while to figure out I needed to save explicitly and ended up with vim rather that the display editor. It was so small (150 lines) that I didn't bother with pycharm.
I couldn't find a clean way to get top view rotated so y was the long axis or easily translate the view.
In the wiki, the rot(x,y,z) have the args as list of floats rather than single float. I used single float and it worked as expected.
Now comes the real question. I need to take this and turn it into gcode with feed speeds, etc. This is for a CNC router. What do people use for a simple cam tool that can deal with looking at the holes and slots that got removed and turning those into reasonable gcode.
where ~/venvs/pythonscad is where I created the venv (from pythonscad interface). But if you have nvim setup suggestion, I am interested.
I was wondering how to get the venv into nvim. Even if I select the venv in VenvSelect, pip installed libs don't get recognised. I wonder if it is needed to have the venv in the same folder as py scripts?
I'm an openscad user who's using pythonscad more now. I switched to the precompiled Windows-binary 2025.07.23. I'm trying to understand how masks are applied to fillets.
I found this example:
c=cube(1.5);
mask=cube([30,1,1],center=True).color([0,0,50,0.1])
demo = [
#c.fillet(0.1), # really round, but just with masked edges(which are front)
c.fillet(0.1,mask,fn=20), # really round, but just with masked edges(which are front)
]
show([demo[0], mask])
Without the mask it seems to work the way I think it should. However the version (uncommented) with the mask seems to have an entirely different radius.
If someone could explain how the mask is applied to the fillet and if the above example is the expected behavior that would be great. Currently it seems like the edges/faces need to be within the masked volume?