Quick Start — 5 Minutes
From a furniture description to working FreeCAD Python code in four steps.
Parameters
Define all dimensions as UPPER_CASE variables.
Coordinates
Set Z elevations and list the expected_objects.
Parts
Part.makeBox → translate → addObject
Validation
Run doc.recompute() and check every object.
# ═══ STAGE 1: PARAMETERS ═══
import FreeCAD
import Part
doc = FreeCAD.ActiveDocument
if doc is None:
doc = FreeCAD.newDocument("TextToCAD")
W = 450 # Cabinet width, mm
D = 400 # Depth
H = 550 # Height
T = 16 # Chipboard thickness
COKOL_H = 60 # Plinth height
# ═══ STAGE 2: COORDINATES ═══
INNER_W = W - 2 * T # 418
Z_DNO_BOT = COKOL_H # 60
Z_DNO_TOP = COKOL_H + T # 76
Z_KRYSHA_BOT = H - T # 534
# Check: 60 + 16 + 458 + 16 = 550 ✓
expected_objects = [
"Bok_LDSP16mm_1", "Bok_LDSP16mm_2",
"Dno_LDSP16mm_1", "Krysha_LDSP16mm_1",
]
# ═══ STAGE 3: PARTS ═══
side_l = Part.makeBox(T, D, H)
side_l.translate(FreeCAD.Vector(0, 0, 0))
obj = doc.addObject("Part::Feature", "Bok_LDSP16mm_1")
obj.Shape = side_l
side_r = Part.makeBox(T, D, H)
side_r.translate(FreeCAD.Vector(W - T, 0, 0))
obj = doc.addObject("Part::Feature", "Bok_LDSP16mm_2")
obj.Shape = side_r
bottom = Part.makeBox(INNER_W, D, T)
bottom.translate(FreeCAD.Vector(T, 0, Z_DNO_BOT))
obj = doc.addObject("Part::Feature", "Dno_LDSP16mm_1")
obj.Shape = bottom
top_p = Part.makeBox(W, D, T)
top_p.translate(FreeCAD.Vector(0, 0, Z_KRYSHA_BOT))
obj = doc.addObject("Part::Feature", "Krysha_LDSP16mm_1")
obj.Shape = top_p
# ═══ STAGE 4: VALIDATION ═══
doc.recompute()
for name in expected_objects:
obj = doc.getObject(name)
if obj is None:
print("FAIL: " + name)
continue
s = obj.Shape
if s.isNull() or not s.isValid() or s.Volume <= 0:
print("FAIL: " + name + " - invalid shape")
else:
bb = s.BoundBox
print("OK: " + name + " | " + str(round(bb.XLength)) + "x" + str(round(bb.YLength)) + "x" + str(round(bb.ZLength)))
Pipeline & Architecture
TextToCAD/FreeCAD Pipeline
The prompt directs the LLM not to "describe a shape" but to generate concrete Python code using the FreeCAD Part API. The code is executed in an isolated sandbox via exec().
4 Architectural Principles
doc.addObject() + expected_objects + final verification via doc.getObject().3 Product Types
Frames, canopies, racks. create_tube, create_tube_z. Fastening: welding.
Wardrobes, dressers, kitchens. Part.makeBox, drill_hole, drill_cup. Fasteners: confirmat screws, dowels, cam locks.
Table with metal frame + wooden top. Combination of A and B.
Input Request Types
Photos + drawings + instructions + parts list. All dimensions known → blocks A–H of the master prompt.
Photographs + W×D×H. Parts derived from proportions per §III. LLM requests confirmation.
"4-drawer dresser, oak, one meter tall". Dimensions from standards in §XVIII. Note: # standard, verify.
"IKEA MALM dresser". LLM performs web search → if assembly instructions found → Type A, otherwise → Type B.
1. Assembly instructions / drawings available?
YES → Type A → proceed to blocks A–H
NO → step 2
2. Photos + overall dimensions (W×D×H) available?
YES → Type B → photo analysis (§III)
NO → step 3
3. Product name/SKU specified?
YES → Type D → web search (§III)
NO → Type C → dimensions from standards (§XVIII)
Data Collection & Research
Web Search Algorithm (Type D) — 5 Steps
"[name] dimensions specifications" → overall dims, material, sections"[name] assembly instructions PDF" → priority source"[name] photo" → 4 angles for analysis"[furniture type] [sections] dimensions" → if exact match not foundPhoto Analysis — 4 Angles
Front: sections, proportions, facades, gaps, handles
Side: depth, overhangs, plinth, thicknesses
Open: drawers, slides, shelves
Rear: back panels, stiffeners
Instruction Analysis — 3 Sections
Parts list → each line = Part.makeBox()
Hardware → determines number of drill_hole() calls
Assembly diagrams → populates joint table
9 Critical Generation Rules
len(shape.Solids) >= 1, shape.Volume > 0, shape.isValid() == True, not shape.isNull()import FreeCAD, import Part, import math — each on its own line.hasattr(), getattr(), setattr(), delattr() — PROHIBITED. Replacement: if 'Shape' in obj.PropertiesList:import FreeCAD import Part.<Type>_<MaterialProfile>_<Number>. ASCII only, ≤32 characters. Cyrillic prohibited."text" + str(value).FreeCAD Sandbox
Prohibited
hasattr(obj, 'Shape')
getattr(obj, 'Shape')
setattr(obj, 'val', x)
delattr(obj, 'val')
Replacement
if 'Shape' in obj.PropertiesList:
obj.Shape # direct access
obj.val = x # direct assignment
# delattr not needed
Part::Feature Naming Convention
_, x. Maximum 32 characters.15, 0.5 mm → 05 (no decimal point).| Keyword | Description | Example |
|---|---|---|
Truba<W>x<H>x<T> | Square/rectangular tube | Stolb_Truba60x40x3_1 |
TrubaKruglD<D>x<T> | Round tube | Nozhka_TrubaKruglD48x3_2 |
LDSP<T>mm | Laminated chipboard | Bok_LDSP16mm_1 |
MDF<T>mm | MDF | Fasad_MDF19mm_1 |
DVP<T>mm | Hardboard / HDF | Zadstena_DVP3mm_1 |
Steklo<T>mm | Glass | Polka_Steklo6mm_1 |
Fanera<T>mm | Plywood | Dno_Fanera18mm_1 |
List<T>mm | Sheet steel | Panel_List2mm_1 |
Furnitura | Hardware / fittings | Petlya_Furnitura_1 |
C21_<T>mm | Corrugated sheet C21 | Proflist_C21_05mm_3 |
4 Code Generation Stages
Parameters → STAGE 2
Coordinates → STAGE 3
Parts → STAGE 4
Validation
STAGE 1Parameter Block
All dimensions as UPPER_CASE variables. Single source of truth. Grouping: overall dims, materials, fasteners, gaps.
# ═══ STAGE 1: PARAMETERS ═══
W = 800 # Width, mm
D = 450 # Depth
H = 930 # Height
T = 16 # Chipboard body
T_BACK = 3 # Hardboard back panel
COKOL_H = 80 # Plinth height
GAP_FASAD = 3 # Gap between facades
GUIDE_W = 13 # Ball-bearing slide width
OFFSET_EDGE = 50 # Fastener edge offset
STAGE 2Coordinates & Z-Marks Block
Formulas derived from Stage 1 parameters. Arithmetic verification of Z-levels. expected_objects list.
# ═══ STAGE 2: COORDINATES ═══
Z_DNO_BOT = COKOL_H # 80
Z_DNO_TOP = COKOL_H + T # 96
Z_KRYSHA_BOT = H - T # 914
INNER_W = W - 2 * T # 768
# Arithmetic check:
# Plinth: 80 + Bottom: 16 + Section: 818 + Top: 16 = 930 ✓
expected_objects = [
"Bok_LDSP16mm_1",
"Bok_LDSP16mm_2",
"Dno_LDSP16mm_1",
"Krysha_LDSP16mm_1",
]
STAGE 3Part Generation
Part by part. Each as a separate block. Holes in the same block via drill_hole. Finalize with: doc.addObject("Part::Feature", name).
# --- Left side panel ---
bok_left = Part.makeBox(T, D, H)
bok_left.translate(FreeCAD.Vector(0, 0, 0))
# Confirmat screw for bottom (through-hole, Z axis)
bok_left = drill_hole(
bok_left,
x=T / 2.0,
y=OFFSET_EDGE,
z=Z_DNO_BOT,
diameter=7.0,
depth=T + 1,
axis="Z"
)
obj = doc.addObject("Part::Feature", "Bok_LDSP16mm_1")
obj.Shape = bok_left
STAGE 4Final Validation
doc.recompute() → check every object from expected_objects → informative messages → raise RuntimeError on failures.
doc.recompute()
error_count = 0
for name in expected_objects:
obj = doc.getObject(name)
if obj is None:
print("FAIL: " + name + " - not found")
error_count += 1
continue
if 'Shape' not in obj.PropertiesList:
print("FAIL: " + name + " - no Shape")
error_count += 1
continue
s = obj.Shape
if s.isNull() or not s.isValid() or len(s.Solids) < 1 or s.Volume <= 0:
print("FAIL: " + name + " - invalid")
error_count += 1
else:
bb = s.BoundBox
print("OK: " + name + " | " +
str(round(bb.XLength, 1)) + "x" +
str(round(bb.YLength, 1)) + "x" +
str(round(bb.ZLength, 1)))
if error_count > 0:
raise RuntimeError(str(error_count) + " object(s) failed")
Elevation Marks & Z-Verification
For each horizontal part, specify bottom and top faces. Layer checksum = H.
# ELEVATION MARKS (Z, mm)
# Z = 0 floor
# Z = 0..80 plinth
# Z = 80 bottom face of base (16 mm chipboard)
# Z = 96 top face of base
# Z = 96..436 lower compartment (340 mm)
# Z = 436 bottom face of shelf 1
# Z = 452 top face of shelf 1
# Z = 2084 bottom face of top panel
# Z = 2100 top face of top panel
# Check: 80+16+340+16+1216+16+400+16 = 2100 ✓
Arithmetic Verification
Function Reference (11 total)
9.1 FreeCAD Part API
| Function | Description | Returns |
|---|---|---|
Part.makeBox(W, D, H) | Box from origin | Part.Shape |
Part.makeCylinder(r, h) | Cylinder along Z-axis from origin | Part.Shape |
shape.translate(Vector) | Translation (mutates shape) | None |
shape.rotate(center, axis, angle) | Rotation (mutates) | None |
shape.cut(other) | Boolean subtraction | Part.Shape |
shape.fuse(other) | Boolean union | Part.Shape |
shape.common(other) | Boolean intersection | Part.Shape |
9.2 create_tube — Hollow Tube
def create_tube(start, end, outer_w, outer_h, t):
"""Hollow rectangular tube from start to end.
outer_w, outer_h — outer cross-section, t — wall thickness.
For square: outer_w == outer_h.
Returns Part.Shape or None."""
direction = end.sub(start)
length = direction.Length
if length < 0.01:
return None
direction.normalize()
inner_w = outer_w - 2 * t
inner_h = outer_h - 2 * t
if inner_w <= 0 or inner_h <= 0:
return None
outer = Part.makeBox(outer_w, outer_h, length)
inner = Part.makeBox(inner_w, inner_h, length + 1)
inner.translate(FreeCAD.Vector(t, t, -0.5))
tube = outer.cut(inner)
tube.translate(FreeCAD.Vector(-outer_w / 2.0, -outer_h / 2.0, 0))
z_axis = FreeCAD.Vector(0, 0, 1)
rotation_axis = z_axis.cross(direction)
if rotation_axis.Length > 1e-6:
dot = z_axis.dot(direction)
dot = max(-1.0, min(1.0, dot))
angle = math.degrees(math.acos(dot))
tube.rotate(FreeCAD.Vector(0,0,0), rotation_axis, angle)
elif direction.z < 0:
tube.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(1,0,0), 180)
tube.translate(start)
return tube
9.3 drill_hole — Fastener Hole
6 drilling directions. BoundBox check ±1 mm. Returns Part.Shape with hole cut out.
| axis | Direction | Description |
|---|---|---|
"Z" | +Z (bottom to top) | Standard for horizontal joints |
"Z_DOWN" | −Z (top to bottom) | Top panel from above |
"X" | +X (left to right) | Into end-grain of horizontal panel from left |
"X_NEG" | −X (right to left) | Into end-grain from right |
"Y" | +Y (front to back) | Hinge cups |
"Y_NEG" | −Y (back to front) | Reverse drilling |
9.4 drill_cup — Hinge Cup
Typical parameters: cup_d=35, cup_depth=12 for overlay hinge. Axes: "Y" (front) or "Y_NEG".
Fastener Reference
| Type | D, mm | Depth, mm | Per joint | Edge offset |
|---|---|---|---|---|
| Confirmat pilot (7×50) | 5.0 | 50 | 2 | 50 mm |
| Confirmat through-hole | 7.0 | T+1 | 2 | 50 mm |
| Confirmat countersink | 10.0 | 3.0 | — | — |
| Dowel D8×30 | 8.0 | 15 (each side) | 2 | 100 mm |
| Cam lock socket | 15.0 | 12.5 | 2 | 50 mm |
| Cam lock bolt | 7.0 | 34 | — | — |
| Hinge cup D35 | 35.0 | 12 | 2–4 per door | 100 mm from edge |
| Shelf pin | 5.0 | 12 | 4 per shelf | 50 mm |
| Ball-bearing slide | 13×45 | — | pair per drawer | — |
Decomposition into Sub-Prompts
>25 Part::Feature or >200 lines → mandatory decomposition. Order: A → B → C → D → E in a single FreeCAD document.
| Complexity | Part::Feature | Lines of code | Recommendation |
|---|---|---|---|
| Low | 1–3 | 20–60 | Single sub-prompt |
| Medium | 4–10 | 60–120 | Single with loops |
| High | 10–25 | 120–200 | 2–3 sub-prompts |
| Very high | 25+ | 200+ | Mandatory decomposition |
Drawer Pattern on Slides
INNER_W = W - 2 * T # between carcass sides
DRAWER_W = INNER_W - 2 * GUIDE_W # minus 2 slides (13 mm each)
DRAWER_BOTTOM_W = DRAWER_W - 2 * T # minus 2 drawer sides
# X position of drawer left side
X_DRAWER_LEFT = T + GUIDE_W # 16 + 13 = 29
# Facade = carcass width - gaps
FASAD_W = W - 2 * GAP_FASAD
FASAD_H = (Z_SECTION_TOP - Z_SECTION_BOT) - 2 * GAP_FASAD
Each drawer: 2× YashikBok + YashikPered + YashikZad + YashikDno + Fasad + 2× Napravl
Niches & Decorative Inserts
Critical Rule
A niche ends exactly at Z = side_height (top of side panels). The top panel rests ON the side panels AND on the niche upper edges simultaneously.
Z_NISHA_TOP = Z_KRYSHA_BOT + T✗ Niche above side panels!
Z_NISHA_TOP = Z_KRYSHA_BOT✓ Flush with side panels
LLM Preambles (6 total)
9 rules + functions + fastener reference + response format. For any task.
For single simple parts. 9 rules in brief.
Mapping parts from instructions → names. Cross-verification.
Standard size reference. Web search. User confirmation.
5 discrepancy categories. Comment # FIXED on every change.
4.1 + selected specialization (4.3/4.4/4.5).
You are an expert in generating Python code for FreeCAD within TextToCAD.
CRITICAL RULES:
1. Solids>=1, Volume>0, isValid(), not isNull()
2. 4 stages: PARAMETERS → COORDINATES → PARTS → VALIDATION
3. import FreeCAD / import Part / import math — each on its own line
4. PROHIBITED: hasattr(), getattr(), setattr(), delattr()
5. One instruction = one line. Indentation: 4 spaces.
6. Names: <Type>_<MaterialProfile>_<N>, ASCII, ≤32 characters
7. All dimensions as variables in STAGE 1
8. Order: create → rotate → translate (NOT the reverse!)
9. No f-strings. String concatenation only.
FORMAT: Python code only. 4 stages. No explanations. No markdown.
Troubleshooting Common Issues
Newlines \n lost during copy-paste. Always use the "Copy code" button. Validation blocks >80 chars without \n.
Replacement: if 'Shape' in obj.PropertiesList:
.cut() removed all volume. Or inner_size >= outer_size in create_tube.
Leg_1 → won't work. Use Nozhka_Truba40x40x2_1 with keyword.
Hole coordinates outside BoundBox ±1 mm. Check part's translate values.
Standard: side panels from Z=0 to Z=H. Base at Z=COKOL_H. Plinth is a decorative strip.
Top panel passes through side panels → overlapping Z-ranges. Recalculate Z-marks.
start == end (length=0) or outer_w <= 2*t (negative cross-section).
Checklist (31 Points)
Full Generation Examples
Example A — Table Frame (Type C)
4 legs (Nozhka_Truba40x40x2_1..4) + 4 frame beams (Frame_Truba40x40x2_1..4) + tabletop (Stoleshnica_LDSP25mm_1). Sub-prompt A: frame via create_tube. Sub-prompt B: tabletop via Part.makeBox.
Example B — Wardrobe 1500×500×2100 (Type B)
Side panels Z=0→2100, base at Z=80, top at Z=2084, shelves at Z=436 and Z=1668. Confirmat screws + dowels via drill_hole. Decomposition: A=carcass, B=back panels, C=doors, D=hardware.
Standard Sizes Reference
Materials
| Material | Thickness | Code |
|---|---|---|
| Chipboard (body) | 16 mm | LDSP16mm |
| Chipboard (countertops) | 25 mm | LDSP25mm |
| Hardboard (back panels) | 3 mm | DVP3mm |
| MDF (facades) | 16–19 mm | MDF16mm |
Gaps
| Gap | Size |
|---|---|
| Between facades | 2–3 mm |
| For slide rails | 12.5–13 mm |
| Top panel overhang | 10–30 mm |
| Plinth | 80 mm (kitchen: 100) |
Standard Overall Dimensions
| Type | H, mm | W, mm | D, mm |
|---|---|---|---|
| Dresser | 800–1000 | 600–1200 | 400–500 |
| Bedside cabinet | 400–550 | 400–600 | 350–450 |
| Two-door wardrobe | 2000–2400 | 800–1200 | 550–600 |
| Writing desk | 750 | 1200–1600 | 600–800 |
| Shelving unit | 1800–2200 | 600–1000 | 250–350 |
| Kitchen base cabinet | 850 | 600 (modular) | 560–600 |
| Tall cabinet (pantry) | 1800–2200 | 400–600 | 350–500 |
Appendix A — Transliteration
| Part meaning | Latin | Usage |
|---|---|---|
| Side panel | Bok | Wardrobes, cabinets |
| Top panel | Krysha | Upper panel |
| Bottom | Dno | Bottom panel |
| Shelf | Polka | Removable shelf |
| Horizontal | Gorizont | Fixed horizontal panel |
| Vertical | Vertikal | Partition |
| Plinth | Cokol | Front strip |
| Door | Dver | Hinged door |
| Facade | Fasad | Drawer front |
| Back panel | Zadstena | Hardboard back |
| Countertop | Stoleshnica | Work surface |
| Drawer side | YashikBok | Drawer side panel |
| Drawer front | YashikPered | Drawer front panel |
| Drawer back | YashikZad | Drawer back panel |
| Drawer bottom | YashikDno | Drawer bottom |
| Niche | Nisha | Decorative insert |
| Leg | Nozhka | Support leg |
| Post | Stolb | Frame post |
| Beam | Balka | Horizontal frame member |
| Rod/Bar | Shtanga | Clothing rod |
| Slide rail | Napravl | Ball-bearing / roller slide |
| Corrugated sheet | Proflist | Cladding |
Appendix B — GOST Tubes
| Type | Dimensions (mm) |
|---|---|
| Square | 20×20×1.5, 25×25×2, 40×40×2, 50×50×2, 50×50×3, 60×60×3, 80×80×4 |
| Rectangular | 40×20×2, 60×40×2, 60×40×3, 80×40×3, 100×50×3 |
| Round | D25×2, D32×2.5, D48×3, D57×3.5, D76×3 |
Appendix C — Changelog
v4.0-FTCAD → v5.0-FTCAD CURRENT
Reference Sources
Based on: v4.0-FTCAD + TCSL v6.0 · Date: 2026-04-06
