Build a LEGO Robot with Claude Code¶
| Category | Creative & Real-World AI Builds |
| Status | ๐ก Partially completed |
| Repo | nextwork-build-a-lego-robot-with-claude-code |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Build a LEGO Robot with Claude Code guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ Creative & Real-World AI Builds
Status: ๐ก Partial
Overview¶
LEGO models can be written as text: an LDraw file is one line per brick, giving its colour, position, rotation, and part file. That makes it easy for code (or an AI) to draft a robot, and just as easy to draft one that can't be built. So the real work here is the independent checker.
Summary¶
The text-to-brick pipeline is built. robot.py writes a 105-part prototype and a 104-part final robot as LDraw files, using only part files from the official LDraw library. validate.py independently checks the library, collisions, stud connectivity, the ground plane, and stability. The prototype fails the way the guide's Studio audit expects (floating antenna, lifted foot, unstable), and the final passes. It also exports a BrickLink Wanted List, a parts list, an isometric render, and a layer-by-layer instruction booklet. For the secret mission, a swappable sleepy face reuses only inventory part/colour pairs. The models weren't opened in BrickLink Studio, priced, or physically built.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Python, LDraw, 3D geometry, Graph connectivity, Stability analysis, BrickLink XML
What I built¶
robot.py: generatesprototype.ldr(visual-first, keeping the guide's audit flaws on purpose),desk-buddy-final.ldr(repaired: wide feet on one ground plane, attached antenna), anddesk-buddy-final-sleepy.ldr.fetch_ldraw.sh: downloads exactly the part files used, plusLDConfig.ldr, from the official LDraw library, so every part reference is checked against real files.validate.py: checks library and colours, collisions (box overlap), connectivity (stud-contact graph, finding floating groups), the ground plane, stability (centre of mass inside the support polygon, with a margin), and the 100โ110 part count. It also writesbricklink-wanted-list.xmlandbom.csv.render.py: an isometric SVG render andinstructions.html, one step per layer.face_swap.py: the secret mission. It proves the second expression swaps only the face module and uses only (part, colour) pairs already in the inventory.docs/: the generated wanted list, parts list, renders, and instruction booklet.
How to run¶
bash build.sh # fetch parts, generate, validate, export to docs/
desk-buddy-final.ldr in BrickLink Studio to continue with the guide's Studio checks, pricing, and Instruction Maker.
Verification¶
I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.
PYTHON=/workspace/nextwork-portfolio/.venv/bin/python bash build.sh
Notes¶
The validator models parts as boxes and connections as full stud-over-stud contact. That's stricter than real LEGO in some places (no clips, hinges, or SNOT) and looser in others (no clutch-strength model), which suits a studs-up desk robot.
What isn't done, and why¶
Several steps couldn't be done here. BrickLink Studio (desktop app) wasn't used: no photorealistic render, no Studio collision/colour/stability validators, no Instruction Maker PDF, and no Used-USD price baseline (that needs a BrickLink account). The parts weren't bought or built, and the guide's Claude Code drafting step was replaced by my own generator. To finish, open the .ldr files in Studio, run its checks, price the Wanted List on BrickLink, and build it.
Original project: https://nextwork.ai/projects/bb801541-7d0b-43ea-97c2-5783ec6f04d0 ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ PYTHON=/workspace/nextwork-portfolio/.venv/bin/python bash build.sh
prototype.ldr: 105 parts
desk-buddy-final.ldr: 104 parts
desk-buddy-final-sleepy.ldr: 103 parts
== prototype audit (expected to FAIL: floating antenna, lifted foot, unstable)
prototype.ldr: {'com': (60, 47), 'margin': 0, 'parts': 105, 'assemblies': 2}
PASS library
PASS collisions
FAIL connectivity
FAIL ground_plane
FAIL stability
PASS part_count_100_110
- 2 separate assemblies; floating group(s) at lines [[109, 110]]
- feet not on one ground plane: bottoms at [0.0, 8.0] LDU
- centre of mass (60, 47) LDU is outside the support polygon
== final
desk-buddy-final.ldr: {'com': (60, 46), 'margin': 34, 'parts': 104, 'assemblies': 1}
PASS library
PASS collisions
PASS connectivity
PASS ground_plane
PASS stability
PASS part_count_100_110
== secret mission
swap out: [('4073', 0, 40.0, 0.0, 296.0), ('4073', 0, 60.0, 0.0, 296.0)]
swap in: [('3023', 0, 40.0, 0.0, 296.0)]
OK: expression swap touches only the face module, reuses inventory part/colour combinations, and the swapped model passes every check
wrote docs/prototype.svg
wrote docs/desk-buddy-final.svg
wrote docs/instructions.html
wrote docs/desk-buddy-sleepy.svg
... [100%]
3 passed in 0.05s
[exit code 0]