Source-linked AI summary

Text-to-CadQuery: A New Paradigm for CAD Generation with Scalable Large Model Capabilities

Haoyang Xie, Feng Ju

arXiv:2505.06507v1cs.AIcs.CVcs.LG

TL;DR

Existing generative CAD methods often use task-specific command sequences that pretrained language models do not directly support, requiring additional processing and training from scratch. This paper generates CadQuery code directly from text and fine-tunes pretrained models on an expanded dataset. It reports improved performance across multiple metrics, including a 69.30% Gemini 2.0 Flash accuracy result.

  • Problem

    Many generative CAD methods use task-specific command sequences that pretrained language models do not directly support, and those sequences require further processing to produce 3D models.

    Source: §1 · p. 1
  • Method

    The authors extend Text2CAD with approximately 170,000 CadQuery annotations and fine-tune six pretrained models to generate executable CadQuery code directly from text.

    Source: §1 · p. 2
  • Results

    Performance improves across geometric and model-based metrics, with Gemini 2.0 Flash accuracy of 69.30%, a 10.5% absolute improvement over the baseline.

    Source: §4.2 · p. 8, §6 · p. 9
  • Takeaways & Limitations

    Direct CadQuery output simplifies the modeling pipeline and allows the method to use pretrained language models rather than training models from scratch.

    Source: §6 · p. 9

    The work focuses on output format, and the authors note a performance drop on the 7B model, likely due to underfitting at the current dataset scale.

    Source: §5 · p. 9

Abstract

from arXiv · show

Computer-aided design (CAD) is fundamental to modern engineering and manufacturing, but creating CAD models still requires expert knowledge and specialized software. Recent advances in large language models (LLMs) open up the possibility of generative CAD, where natural language is directly translated into parametric 3D models. However, most existing methods generate task-specific command sequences that pretrained models cannot directly handle. These sequences must be converted into CAD representations such as CAD vectors before a 3D model can be produced, which requires training models from scratch and adds unnecessary complexity. To tackle this issue, we propose generating CadQuery code directly from text, leveraging the strengths of pretrained LLMs to produce 3D models without intermediate representations, using this Python-based scripting language. Since LLMs already excel at Python generation and spatial reasoning, fine-tuning them on Text-to-CadQuery data proves highly effective. Given that these capabilities typically improve with scale, we hypothesize that larger models will perform better after fine-tuning. To enable this, we augment the Text2CAD dataset with 170,000 CadQuery annotations. We fine-tune six open-source LLMs of varying sizes and observe consistent improvements. Our best model achieves a top-1 exact match of 69.3%, up from 58.8%, and reduces Chamfer Distance by 48.6%. Project page: https://github.com/Text-to-CadQuery/Text-to-CadQuery.

1 Introduction

The introduction proposes generating executable CadQuery code directly from natural language instead of using task-specific command sequences. It presents a 170,000-pair dataset and fine-tuning results that motivate using pretrained models and scaling them for CAD generation.

1 Introduction

  • CadQuery is a pure-Python package with a high-level API for common CAD operations, executable without external software dependencies.The authors select it as a representation that is both executable and interpretable for generative modeling.Source: §1 · p. 2
  • The smallest model achieved higher CAD-generation accuracy than Text2CAD with 58 minutes of training versus two days.The introduction contrasts this with Text2CAD’s task-specific decoder, which has approximately 363M parameters.Source: §1 · p. 2
  • Generation accuracy increased with model size across the six fine-tuned models, supporting the authors’ scaling hypothesis.The models range from 124 million to 7 billion parameters.Source: §1 · p. 2
  • The authors extended Text2CAD-augmented DeepCAD with approximately 170,000 text–CadQuery pairs and fine-tuned six pretrained models.The models span 124 million to 7 billion parameters; Mistral-7B uses LoRA.Source: §1 · p. 2
  • The proposed approach generates executable CadQuery code directly from natural language, bypassing intermediate task-specific command sequences.The authors argue this lets pretrained models use their Python-generation and spatial-reasoning capabilities.Source: §1 · p. 2

2 Related Work

Related work surveys generative CAD datasets and output representations, alongside the capabilities of pretrained models relevant to CAD. The paper adopts text input and highlights the need for larger, more diverse CadQuery datasets than earlier symbolic-CAD efforts provide.

Datasets and Methods for Generative CAD

  • Generative CAD datasets now include conditional inputs such as text, images, sketches, and point clouds, with outputs including command sequences, B-rep structures, and scripts.The section points to Table 1 for an overview of datasets by input condition, CAD representation, and model size.Source: §2 · p. 3, Table 1 · p. 3
  • Prior findings report that text-only input outperforms image-based and multimodal combinations in current generative CAD settings, motivating text as this paper’s sole input.The cited work attributes this finding to the field’s early stage, limited datasets, and models that are not yet highly specialized.Source: §2 · p. 3
  • Query2CAD provides 57 samples, while LLM4CAD has around 5,000 samples limited to five common mechanical parts.The authors identify these dataset size and scope constraints as motivation for a larger, more diverse dataset.Source: §2 · p. 3

General Capabilities of Large Models Enabling CAD Modeling

  • Pretrained models’ multimodal understanding, spatial reasoning, and code synthesis motivate using them with high-level CAD representations.The section describes these capabilities as a basis for generating CAD from high-level descriptions and evaluating models at different scales.Source: §2 · p. 4

3 Method

The method builds a semi-automatic pipeline to annotate Text2CAD examples with CadQuery, then fine-tunes pretrained models selected for CadQuery familiarity and scale. Training adapts to model size and uses token-level cross-entropy, with geometry evaluated after training.

3.1 Data Annotation

  • The dataset builds on DeepCAD and Text2CAD, and the annotation pipeline adds CadQuery code to the 170,000-sample dataset.DeepCAD supplies CAD command sequences, while Text2CAD adds natural-language descriptions at multiple levels of detail.Source: §3.1 · pp. 4–5
  • Gemini converts structured minimal JSON to CadQuery, executes the code, receives error feedback for corrections, and uses rendered-shape comparison plus human review to validate annotations.The feedback loop raises execution success from 53% to 85%; accepted annotations are used to annotate the 170,000-sample dataset.Source: §3.1 · pp. 4–5
  • GPT-4o produces over 90% executable outputs on the first attempt, while Claude and Gemini show comparable accuracy with feedback at approximately 85%.The authors select Gemini 2.0 Flash for annotation based on its ability to translate structured minimal JSON into executable CadQuery code.Source: §3.1 · p. 5

3.2 Pretrained Model Selection

  • Model selection considers prior CadQuery familiarity and parameter scale, spanning decoder-only models from 124M to 7B parameters.The evaluated models include CodeGPT-small, GPT-2 medium and large, Gemma3-1B, Qwen2.5-3B, and Mistral-7B.Source: §3.2 · pp. 5–6

3.3 Fine-Tuning Setup

  • The authors split data 90%/5%/5% for training, validation, and testing, using full-parameter SFT for smaller models and LoRA-based PEFT for larger ones.LoRA adds learned low-rank matrices to attention layers while keeping base weights frozen, enabling efficient adaptation on limited hardware.Source: §3.3 · p. 6
  • 94.09% of samples are shorter than 1024 tokens, so fine-tuning uses a 1024-token context length; training uses token-level cross-entropy and evaluates geometry after training.Shorter inputs are padded and longer ones truncated to the context length.Source: §3.3 · p. 6, Figure 3 · p. 6

4 Results and Evaluation

The evaluation compares CadQuery generation with the Text2CAD Transformer and assesses geometric fidelity, execution validity, and visual similarity. Qwen2.5-3B achieves the best overall results, while accuracy rises with model size through 3B and the 7B model does not improve further.

4.2 Evaluation Metrics

  • Evaluation uses Chamfer Distance, Invalid Rate, and Gemini 2.0 Flash, supplemented by F1 Score for local alignment and volumetric IoU for global overlap.F1 uses 10,000 sampled surface points and a fixed threshold of τ = 0.02; IoU compares voxelized meshes.Source: §4.2 · pp. 7–9

4.1 Baseline: Text2CAD Transformer

  • CodeGPT-small (124M) consistently outperforms the Text2CAD Transformer across all metrics, despite using a model of similar or smaller size.The comparison uses the same textual inputs; Text2CAD generates task-specific command sequences, while this method generates CadQuery code.Source: §4.2 · p. 7, §4.1 · p. 7

4.2 Evaluation Metrics

  • Qwen2.5-3B achieves the best overall results: Chamfer Distance 0.191 (median) and 10.229 (mean) after ×103, with Gemini 2.0 Flash accuracy of 69.30%, a 10.5% absolute improvement over baseline.Table 3 compares models on Chamfer Distance and Gemini 2.0 Flash Evaluation.Source: §4.2 · pp. 7–8, Table 3 · p. 8
  • Mistral has the lowest Invalid Rate at 1.32, while GPT-4.1 mini reaches 0% Invalid Rate after fine-tuning on 10k examples but matches 7B-model accuracy.The authors interpret this pattern as greater execution reliability in advanced models but a continued need for sufficient data to learn precise 3D generation.Source: §4.2 · p. 8
  • Qwen2.5-3B leads on both Figure 4 metrics, with F1 median 0.9836 and volumetric IoU median 0.9868.CodeGPT-small reaches F1 median 0.9688.Source: Figure 4 · p. 8, §4.2 · p. 9
  • Accuracy improves steadily as model size rises from 124M to 3B, but 7B Mistral does not improve over Qwen2.5-3B, likely because limited data causes underfitting.The authors describe this as a tradeoff between model capacity and data availability in symbolic 3D generation.Source: §4.2 · p. 9

5 Limitation

The paper focuses on output format and identifies data scale as a limitation. Extending evaluation to other inputs or larger models would require additional annotations and computational resources.

5 Limitation

  • The study focuses on output format and reports that CadQuery outperforms task-specific command sequences.The authors say the approach could extend to images, sketches, and point clouds, but note that additional CadQuery annotations would be valuable to test this across input types.Source: §5 · p. 9
  • Despite 170,000 samples, performance drops on the 7B model, which the authors attribute likely to underfitting.They suggest scaling up the dataset to test this hypothesis.Source: §5 · p. 9
  • Testing 13B or 32B models would require significant annotation effort and computational resources.The authors present larger models as a possible future test, not an established improvement.Source: §5 · p. 9

6 Conclusion

The paper concludes that direct CadQuery generation simplifies CAD modeling and performs well across multiple evaluations. Its experiments report improvements over Text2CAD and a scaling trend in accuracy and executability.

6 Conclusion

  • The approach simplifies the modeling pipeline by generating executable CadQuery code directly instead of task-specific command sequences.The authors report improved performance across multiple geometric and model-based evaluation metrics.Source: §6 · p. 9
  • The 170,000 text–CadQuery-pair dataset supports direct training with pretrained language models rather than training models from scratch.The paper reports faster training and better generalization from adopting pretrained models.Source: §6 · p. 9
  • Even the smallest fine-tuned model outperforms the Text2CAD baseline, while accuracy and executability show a clear upward trend with model size.The authors report that their best model achieves state-of-the-art results across multiple metrics.Source: §6 · p. 9
  • CadQuery output is positioned to benefit from future advances in foundation-model multimodal understanding, spatial reasoning, and code generation without changes to the training framework or output design.The authors also identify extending generation to diverse inputs and larger models as future directions.Source: §6 · p. 9

A.1 Background: CAD Command Sequence Representation

Prior CAD-generation methods represent models as fixed-length sequences of parametric commands. Those sequences are encoded for model training and then converted into structured representations used to generate CAD geometry.

A.1 Background: CAD Command Sequence Representation

  • DeepCAD and Text2CAD represent CAD models as fixed-length sequences of commands describing construction operations such as drawing curves and extruding solids.The commands function like a CAD modeling history.Source: §A.1 · p. 13
  • The representation defines six command types, including Line, Arc, Circle, Extrude, and sequence or loop markers, with up to 16 parameters per command.Parameters include geometry such as position, radius, angles, extrusion depth, and boolean type.Source: §A.1 · p. 13
  • Parameters are normalized and quantized into 256 bins; commands are embedded with type, parameter, and position encodings, then padded or truncated to a fixed length.The typical sequence length is 60.Source: §A.1 · p. 13
  • After generation, the discrete sequence is converted into a structured format, such as nested JSON or a fixed-length CAD vector, for geometry generation.Downstream CAD utilities can produce a mesh or point cloud from the structured representation.Source: §A.1 · pp. 13–14

A.2 Comparison and Examples of Parametric CAD Tools

The paper compares parametric CAD tools for scripting and Python-pipeline integration, and identifies CadQuery as the best trade-off between usability and flexibility.

A.2 Comparison and Examples of Parametric CAD Tools

  • CadQuery offers the best trade-off between usability and flexibility among the compared tools for programmatic shape synthesis.Table 4 summarizes scripting capabilities and integration potential with Python-based pipelines; its caption identifies it as a comparison of parametric CAD tools.Source: §A.2 · p. 14, Table 4 · p. 14
  • The comparison considers parametric CAD tools' scripting capabilities and their potential integration with Python-based pipelines.The supplied passage does not state specific table entries beyond the overall CadQuery assessment.Source: §A.2 · p. 14
  • The table is titled as a comparison of parametric CAD tools.The caption does not specify row or column encodings.Source: Table 4 · p. 14

FreeCAD

The example creates a FreeCAD document, makes a box, displays it, and recomputes the document.

FreeCAD

  • The FreeCAD snippet creates a document, constructs a 10-by-10-by-10 box, displays it, and recomputes the document.It uses FreeCAD and Part imports, then calls newDocument, makeBox, show, and recompute.Source: FreeCAD · p. 14

OpenSCAD

The appendix contrasts Python CAD code examples, shows CAD-sequence JSON translated into CadQuery, and documents a numerically unstable arc-construction failure with suggested mitigations.

CadQuery

  • The CadQuery and PythonOCC examples create a box using different Python APIs, then display or export the resulting geometry.The CadQuery snippet exports an STL, while the PythonOCC snippets display the box.Source: CadQuery · p. 14, PythonOCC · p. 14

A.3 Prompt Design

  • The prompt-design appendix introduces examples that convert a CAD-sequence JSON representation into CadQuery code.The examples include a cylinder and a more complex prism with a curved top and a cutout.Source: §A.3 · p. 15

1. CAD Sequence (JSON)

  • The first JSON example specifies a cylinder through its sketch radius, extrusion depth, scale, operation, and dimensions.Its part definition also includes a coordinate frame and translation vector.Source: §1 · p. 15

1. CadQuery Code

  • The corresponding CadQuery example scales the cylinder radius, extrudes it, and exports the result as an STL.It imports CadQuery and constructs the part on the XY workplane.Source: §1 · p. 15

2. CAD Sequence (JSON)

  • The second JSON example describes a prism with a curved top and side cutout using line and arc sketch elements, an extrusion, and a transformed coordinate frame.The sequence includes the extrusion depth and final part dimensions.Source: §2 · p. 16

2. CadQuery Code

  • The second CadQuery example applies a rotation and translation to the part before exporting the assembly as an STL.Its prompt specifies executable Python code only, beginning with an import.Source: §2 · p. 17

Failure code

  • The failure-code example uses threePointArc for a tiny arc, the construction that the appendix identifies as vulnerable to floating-point precision limits.The shown snippet also sets sketch scale and extrusion depth and adds holes.Source: §A.4 · p. 17, Failure code · p. 18

A.4 Failure case example

  • Nearly colinear, very small arc-control points can trigger OpenCascade construction failures; the paper suggests increasing sketch scale or using radiusArc, splines, or polylines.The authors also call for training on more diverse, numerically challenging CAD data.Source: §A.4 · pp. 17–18
Loading 2505.06507v1…