Text-to-CAD Usage Examples: Complete Guide to SDF, URDF, STEP, and Implicit-JS Generation
The text-to-CAD repository provides self-contained example scripts in skills/sdf/references/examples.md, packages/implicitjs/README.md, and skill documentation files that demonstrate how to generate SDF, URDF, STEP/CAD, and implicit-JS models.
The text-to-CAD project by earthtojake bundles canonical example files directly alongside its core skills and packages. These examples serve as the primary reference for converting natural language prompts into machine-readable CAD formats. Whether you're building robot simulation descriptions or generating manufacturable geometry, the repository's documented snippets show exactly how to invoke the underlying APIs and CLI tools.
SDF Generation Examples
The SDF (Simulation Description Format) skill contains the most extensive collection of text-to-CAD usage examples. Located at skills/sdf/references/examples.md, these scripts demonstrate both low-level XML construction and the higher-level Python builder API.
Raw ElementTree Approach
For maximum control, the examples first show direct xml.etree.ElementTree manipulation:
import xml.etree.ElementTree as ET
def text(parent, tag, value, attrib=None):
child = ET.SubElement(parent, tag, attrib or {})
child.text = str(value)
return child
def gen_sdf():
sdf = ET.Element("sdf", {"version": "1.12"})
model = ET.SubElement(sdf, "model", {"name": "calibration_box"})
text(model, "pose", "0 0 0 0 0 0", {"relative_to": "world"})
# … additional link / visual / collision / inertial definitions …
return {"xml": sdf, "assumptions": ["Box inertia uses a uniform-density primitive approximation."]}
This pattern appears at lines 7-47 of the examples file and establishes the foundational structure that all SDF generators must produce: a versioned root element, named model container, and pose-relative placement.
Helper API for Complex Robots
The builder API abstracts repetitive ElementTree calls into composable functions. The two-link robot example (lines 76-128) demonstrates idiomatic text-to-CAD patterns:
from sdf.builder import (
box, collision, inertial, joint, link, model, pose, sdf_root, visual,
)
BASE_MASS_KG = 2.0
ARM_MASS_KG = 0.5
def gen_sdf():
sdf = sdf_root("1.12")
robot = model(sdf, "two_link_demo")
pose(robot, relative_to="world")
base = link(robot, "base_link")
box(visual(base, "base_visual"), (0.4, 0.3, 0.1))
box(collision(base, "base_collision"), (0.4, 0.3, 0.1))
inertial(base, BASE_MASS_KG, (0.02, 0.03, 0.04, 0, 0, 0))
arm = link(robot, "arm_link")
box(visual(arm, "arm_visual"), (0.3, 0.05, 0.05))
box(collision(arm, "arm_collision"), (0.3, 0.05, 0.05))
inertial(arm, ARM_MASS_KG, (0.001, 0.004, 0.004, 0, 0, 0))
joint(robot, "shoulder_pan", "revolute", "base_link", "arm_link",
axis_xyz=(0, 0, 1), axis_expressed_in="base_link")
return {"xml": sdf, "assumptions": ["Primitive inertials are approximate placeholders."]}
Key patterns to adopt:
- Import the complete
sdf.buildernamespace for discoverability - Define physical constants at module scope
- Return both the XML root and a list of modeling assumptions for downstream validation
Implicit-JS Model Examples
For neural implicit representations, the packages/implicitjs directory contains JavaScript examples that demonstrate the signed distance field (SDF) construction API. The canonical file is examples/model.implicit.js, referenced in packages/implicitjs/README.md at lines 119-135.
Basic Scene Composition
// examples/model.implicit.js
import { implicit_sphere, implicit_box_centered, implicit_union_round } from "implicitjs";
export default function scene() {
const sphere = implicit_sphere([0, 0, 0], 0.5);
const box = implicit_box_centered([0, 0, 0.75], [0.3, 0.3, 0.3]);
return implicit_union_round([sphere, box], 0.1);
}
This example demonstrates three core concepts:
- Primitive generators (
implicit_sphere,implicit_box_centered) that accept position and dimension parameters - Boolean operations (
implicit_union_round) that combine primitives with blend radii - Default export convention that the CLI tools expect
CLI Execution Patterns
The README documents how to process these models through npm scripts:
# Render a snapshot PNG
npm --prefix packages/implicitjs run snapshot -- --input examples/model.implicit.js --output /tmp/model.png
# Export to manufacturing formats (GLB, STL, or 3MF)
npm --prefix packages/implicitjs run export -- --input examples/model.implicit.js --format glb --output /tmp/model.glb
The --prefix flag routes commands into the correct package directory without changing your working directory.
CAD and URDF Skill Entry Points
While SDF and implicit-JS provide complete runnable scripts, the CAD (STEP/build123d) and URDF skills document their text-to-CAD usage patterns in their respective SKILL.md front-matter files.
skills/cad/SKILL.md– Describes CLI entry points for generating STEP files and build123d scripts, including selector syntax for targeting specific geometry featuresskills/urdf/SKILL.md– Documents URDF generation workflows and cross-references example patterns
These files intentionally reference rather than duplicate the full examples, ensuring documentation stays synchronized with the evolving codebase. The CLI tools (python scripts/cad ... and python scripts/urdf ...) pull configuration and validation logic directly from these skill definitions.
Where to Find Updated Text-to-CAD Examples
The repository maintains examples as living documentation—they update in lockstep with API changes. Primary locations:
| Format | File Path | Content Type |
|---|---|---|
| SDF | skills/sdf/references/examples.md |
Raw ET and builder API patterns |
| Implicit-JS | packages/implicitjs/README.md → examples/model.implicit.js |
JavaScript SDF composition + CLI commands |
| CAD/STEP | skills/cad/SKILL.md |
CLI reference and selector syntax |
| URDF | skills/urdf/SKILL.md |
Generation workflow and cross-references |
| Package index | packages/README.md |
All shared Python/JS packages |
When the repository evolves, these files constitute the canonical source of truth for text-to-CAD usage.
Summary
- SDF examples in
skills/sdf/references/examples.mddemonstrate both rawxml.etree.ElementTreeconstruction and the higher-levelsdf.builderAPI for robot description generation - Implicit-JS examples at
examples/model.implicit.jsshow signed distance field composition withimplicit_sphere,implicit_box_centered, andimplicit_union_roundprimitives - CLI tools across all skills consume these example patterns—use
npm --prefix packages/implicitjsfor JavaScript workflows andpython scripts/<skill>for Python-based generation - SKILL.md files in
skills/cad/andskills/urdf/provide entry-point documentation that stays synchronized with implementation changes
Frequently Asked Questions
Where are the complete runnable scripts for text-to-CAD?
The complete scripts reside in skills/sdf/references/examples.md for SDF generation and examples/model.implicit.js for implicit-JS models. These files contain copy-paste-ready code that executes without modification when passed to the respective CLI tools.
Can I use text-to-CAD without the builder API?
Yes. The examples in skills/sdf/references/examples.md lines 7-47 demonstrate direct xml.etree.ElementTree manipulation. This approach requires more verbose code but provides complete control over attribute ordering and namespace handling.
What output formats does the implicit-JS package support?
According to packages/implicitjs/README.md, the export command supports GLB, STL, and 3MF formats. Specify your target with --format <extension> when invoking the CLI.
How do I add physical properties like mass and inertia to SDF models?
Use the inertial() builder function (shown in lines 76-128 of the SDF examples) or manually construct <inertial> elements with <mass> and <inertia> children. The builder API accepts a mass float and a 6-element inertia tuple (ixx, iyy, izz, ixy, ixz, iyz).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →