TriView2CAD-Code
Dimensioned orthographic engineering drawings -> executable CadQuery code. 200,000 samples of prefabricated bridge piers (160,000 train / 40,000 test), each a 1475x1475 three-view drawing (front / top / side) with every dimension annotated, paired with a CadQuery program that rebuilds the part exactly.
input one PNG holding the front, top and side views, fully dimensioned
output CadQuery (Python) source; executing it yields the corresponding solid
Schema (the team's unified 7-field SFT schema)
| field | content |
|---|---|
query |
the instruction (a single fixed prompt across the set) |
image |
1475x1475 PNG, bytes embedded |
annot |
CadQuery source -- the gold / SFT target |
reasoning |
null (no native chain-of-thought in this set) |
cate / task |
E / T-E1 -- CAD code generation |
metadata |
JSON string: the full upstream parameter table, field-name mapping, topology, provenance, evaluation note |
from datasets import load_dataset
ds = load_dataset("AI4Manufacturing/triview2cad_code", split="train") # or split="test"
print(ds[0]["annot"])
ds[0]["image"] # PIL image
The task
Each drawing is generated from a 15-dimensional parameter vector describing one prefabricated bridge pier. The model must read the annotated dimensions off the drawing and emit code that reproduces the geometry. Three abilities are involved:
- dimension recognition -- map each annotated number to the feature it measures
- primitive counting -- how many pier columns, how many pile bases
- composite computation -- the drawing annotates segments; several parameters are
their sums (e.g. the cap-beam width is
2*margin + 2*column_width + clear_gap), and the pile radius is annotated as a diameter
Structure
Three stacked layers, top to bottom:
pier columns rounded-rect prisms, filleted; 1 or 2 of them
----------------
| cap slab | rect_width x rect_height x cap_height
----------------
| | pile bases cylinders, (1..3) x (2..3) grid
Code provenance -- please read
CadQuery reimplementation. The upstream TriView2CAD pipeline builds its 3D models with the FreeCAD Python API (paper arXiv:2506.00568 sec 3.1 Step 3), but that modelling script was never released -- the public ModelScope drop contains only metadata.json, dxf_files.zip and img_files.zip. This code was regenerated from the parameter table by gen_cadquery.py: geometry-equivalent, but the code text has no correspondence to any upstream artefact.
The geometry rules were verified against the published drawings, not assumed:
- three drawings checked annotation by annotation (ids 1, 23, 12 -- covering component counts of 2, 3 and 1, i.e. every placement rule)
- all 12 structural topologies built and their bounding boxes checked against the parameters
- all 200,000 records checked arithmetically: no component escapes the cap footprint, no fillet radius exceeds half-width, no two components overlap
- a random sample executed in CadQuery, bounding boxes matching the parameter table exactly
The generator is gen_cadquery.py, shipped alongside the converter; it is the only
provenance for this column. Editing it changes the dataset.
Surface-form diversity -- 972 code forms, 50 prompts
A single template would teach a model to recite boilerplate rather than write valid CadQuery:
in a first version of this set the annot column compressed 6.8x in parquet, meaning roughly
800 of every 923 bytes repeated verbatim across all 200,000 records.
The code is therefore generated across six independent dimensions -- variable naming (4), cap construction (3), component placement (3), statement organisation (3), merge style (3) and comments (3):
4 x 3 x 3 x 3 x 3 x 3 = 972 forms, about 206 occurrences each
Enough for a model to learn each as a legitimate way to write CadQuery, too few for any one form to be worth memorising. Two forms picked at random share a median of 0.64 of their text, and only 0.8% of pairs exceed 0.95. Every one of the 972 was executed and compared: the solids are identical -- only the surface form varies, never the geometry.
Six consecutive records, showing what that looks like in practice:
pile_cap = cq.Workplane("XY").rect(860, 833).extrude(341) # named vars + list of columns
cap = cq.Workplane("XY").box(920, 941, 284, centered=(True, True, False))
column0 = cq.Workplane("XY").workplane(offset=272).center(-214, 0)...
bodies = [ ... ] # one flat list, reduce() to merge
cap = cq.Workplane("XY").box(804, 849, 252).translate((0, 0, 126))
pieces = [ ... ]
The prompt varies the same way: 50 variants, about 4,000 uses each, seeded independently of the code style (chi-square 5.7 against a 15.5 critical value, so the two are uncorrelated -- a correlation would let a model learn a spurious "this wording implies that code shape" rule). All 50 differ in wording, length, register and terminology, but ask for the same thing.
Evaluation
One solid admits many valid CadQuery programs, so exact string match against annot is NOT a valid score; execute the prediction and compare geometry. The final solid is bound to the variable solid; evaluation may append cq.exporters.export(solid, ...) to the generated code.
Known limits
- One part family. Everything is a prefabricated bridge pier. The parameter space is 15 fields with fixed semantics; nothing here transfers to another kind of part.
- 12 structural topologies. The counts take only
pier columns in {1,2}andpile bases in {1,2,3} x {2,3}-- 12 combinations, sampled in an even 1/12 split. The 200,000 samples differ almost entirely in dimension values, not in structure. - Synthetic only. The upstream paper also reports 3,000 real-world drawings used as an out-of-distribution test set, but those were never released -- the public drop is the 200,000 synthetic samples alone, so the paper's OOD result cannot be reproduced from here.
- The split is ours, not the paper's. The paper states an 80/20 split of the synthetic
set but never published the assignment (the released
metadata.jsonis one flat file, ids 1..200,000, no split field). This dataset follows the same 80/20 ratio with a plain random shuffle under a fixed seed (20260919, recorded inmanifest.jsontogether with a fingerprint of the assignment). There is therefore no id-level correspondence to the paper's split, and numbers measured here cannot be compared with the paper's. - The test split measures fit, not generalisation. Both splits are drawn from the same generator, the same 12 topologies and the same parameter distribution -- they are i.i.d. A high test score says the training distribution was fitted, not that the model can read an engineering drawing. The paper's own figures make the gap concrete: 76% on its synthetic test versus 36% on real drawings.
- Units. Values are integers exactly as annotated on the drawing; no unit is declared upstream.
Licensing
Upstream TriView2CAD is published on ModelScope under CC-BY-NC-4.0. That is a non-commercial licence and it carries over to this derivative, which is therefore also released as CC-BY-NC-4.0. Research use only; check the upstream terms before relying on it commercially.
Provenance
Real bridge-pier CAD archives
| expert analysis -> 15-D parameter space + intra-/inter-view constraints
v
Constraint-guided sampling -> 200,000 parameter vectors
|
+-- ezdxf -> DXF -> FreeCAD render -> three-view PNG (upstream)
+-- FreeCAD Python API -> STEP / B-Rep (upstream, unreleased)
+-- gen_cadquery.py -> CadQuery source (this repo)
Source dataset: zhuofanChen/TriView2CAD
Citation
Please cite the original work:
@inproceedings{niu2025creftcad,
title={CReFT-CAD: Boosting Orthographic Projection Reasoning for CAD via
Reinforcement Fine-Tuning},
author={Niu, Ke and Chen, Zhuofan and Yu, Haiyang and Chen, Yuwen and Fu, Teng
and Zhao, Mengyang and Li, Bin and Xue, Xiangyang},
booktitle={NeurIPS}, year={2025}
}
- Downloads last month
- -