Table of Contents
Fetching ...

CAD-Coder:Text-Guided CAD Files Code Generation

Changqi He, Shuhan Zhang, Liguo Zhang, Jiajun Miao

TL;DR

CAD-Coder addresses the challenge of generating interactive, editable CAD content from natural language by translating NL prompts into Python scripts that construct DXF files via the ezdxf library. It introduces the CFSC dataset with 29,130 DXF samples and corresponding script codes and NL descriptions to support editable and annotated CAD sketches and 3D models. Using a distillation-based DeepSeek-R1-Distill-Llama-8B backbone with LoRA fine-tuning, CAD-Coder achieves strong cross-platform DXF generation and robust annotation capabilities, outperforming several baselines in geometry and annotation quality. The work demonstrates practical impact for rapid, personalized CAD design across platforms, and outlines future expansions to cover more components and annotation types.

Abstract

Computer-aided design (CAD) is a way to digitally create 2D drawings and 3D models of real-world products. Traditional CAD typically relies on hand-drawing by experts or modifications of existing library files, which doesn't allow for rapid personalization. With the emergence of generative artificial intelligence, convenient and efficient personalized CAD generation has become possible. However, existing generative methods typically produce outputs that lack interactive editability and geometric annotations, limiting their practical applications in manufacturing. To enable interactive generative CAD, we propose CAD-Coder, a framework that transforms natural language instructions into CAD script codes, which can be executed in Python environments to generate human-editable CAD files (.Dxf). To facilitate the generation of editable CAD sketches with annotation information, we construct a comprehensive dataset comprising 29,130 Dxf files with their corresponding script codes, where each sketch preserves both editability and geometric annotations. We evaluate CAD-Coder on various 2D/3D CAD generation tasks against existing methods, demonstrating superior interactive capabilities while uniquely providing editable sketches with geometric annotations.

CAD-Coder:Text-Guided CAD Files Code Generation

TL;DR

CAD-Coder addresses the challenge of generating interactive, editable CAD content from natural language by translating NL prompts into Python scripts that construct DXF files via the ezdxf library. It introduces the CFSC dataset with 29,130 DXF samples and corresponding script codes and NL descriptions to support editable and annotated CAD sketches and 3D models. Using a distillation-based DeepSeek-R1-Distill-Llama-8B backbone with LoRA fine-tuning, CAD-Coder achieves strong cross-platform DXF generation and robust annotation capabilities, outperforming several baselines in geometry and annotation quality. The work demonstrates practical impact for rapid, personalized CAD design across platforms, and outlines future expansions to cover more components and annotation types.

Abstract

Computer-aided design (CAD) is a way to digitally create 2D drawings and 3D models of real-world products. Traditional CAD typically relies on hand-drawing by experts or modifications of existing library files, which doesn't allow for rapid personalization. With the emergence of generative artificial intelligence, convenient and efficient personalized CAD generation has become possible. However, existing generative methods typically produce outputs that lack interactive editability and geometric annotations, limiting their practical applications in manufacturing. To enable interactive generative CAD, we propose CAD-Coder, a framework that transforms natural language instructions into CAD script codes, which can be executed in Python environments to generate human-editable CAD files (.Dxf). To facilitate the generation of editable CAD sketches with annotation information, we construct a comprehensive dataset comprising 29,130 Dxf files with their corresponding script codes, where each sketch preserves both editability and geometric annotations. We evaluate CAD-Coder on various 2D/3D CAD generation tasks against existing methods, demonstrating superior interactive capabilities while uniquely providing editable sketches with geometric annotations.
Paper Structure (19 sections, 20 equations, 13 figures, 5 tables)

This paper contains 19 sections, 20 equations, 13 figures, 5 tables.

Figures (13)

  • Figure 1: Comparison of CAD-Coder with current works. Comparing with other CAD generation methods, CAD-Coder uses a different form of dataset and produces more easily editable and annotated CAD models.
  • Figure 2: Pipeline of the CAD-Coder. By randomly assigning values to the free parameters in the parent code, a series of script codes along with their corresponding Dxf files are generated, forming the CFSC Dataset. The dataset contains both 3D models and 2D sketches, especially contains annotated data. The codes in dataset are matched with their corresponding natural language descriptions, from which relevant question-answer pairs were extracted and injected into the DeepSeek-R1-Distill-Llama-8B model. Through training with the LoRA method, the model acquired the ability to infer CAD script code. Users can query the model to obtain the desired CAD script code, which can then be executed to generate Dxf files. These files can be opened and edited on various platforms.
  • Figure 3: Quantities of Different Primitive Types. LA stands for linear annotation, AA is angle annotation, and RA is radius annotation.
  • Figure 4: Script code structure illustration. The script code for each Dxf file consists of: (1) importing library functions, (2) the model construction function, and (3) the main function. The model construction function is responsible for defining the script code framework, including both model construction and adding annotations. The main function is used to call the model construction function, define the required dimensional parameters.
  • Figure 5: Handling of similar script code segments. Comments are added to script code segments that are prone to confusion, making it easier for the model to differentiate between these data.
  • ...and 8 more figures