# Can text-to-cad Generate STEP Files? A Complete Guide to CAD Export

> Discover if text-to-cad can generate STEP files. This guide details using the scripts/step CLI to convert Python sources or import existing STEP files for CAD.

- Repository: [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad)
- Tags: how-to-guide
- Published: 2026-07-24

---

**Yes, text-to-cad can generate STEP files** using the `scripts/step` CLI, which either converts Build123d Python sources into STEP format or imports existing STEP/STP files to create GLB topology artifacts for the CAD Viewer.

The earthtojake/text-to-cad repository provides a complete toolchain for STEP file generation and management, enabling both programmatic CAD creation from Python scripts and seamless integration with the web-based CAD Viewer. This workflow centers on the **cadpy** Python package and its `step_artifact` module, which handles the actual file serialization and catalog registration.

## How text-to-cad Generates STEP Files

The system operates through two distinct pathways depending on your source material. Both pathways utilize the `scripts/step` command-line interface and ultimately invoke `cadpy.step_artifact` to write files to the filesystem.

### Generating STEP Files from Python Sources

When working with Build123d-based Python files, the system expects a `gen_step()` function that returns a `build123d` shape or compound. Running the CLI against these files executes the Python code, captures the geometric result, and exports it as a STEP file. The tool automatically detects whether the source represents a single part or an assembly based on the `--kind` parameter.

### Importing Existing STEP Files

If you already possess STEP or STP files, the CLI can import them directly without requiring a Python generator. This workflow creates a hidden GLB topology side-car file that enables preview and inspection within the CAD Viewer interface, effectively bridging legacy CAD assets into the text-to-cad ecosystem.

## Using the scripts/step CLI

The `scripts/step` utility provides flexible output control and supports batch operations. Located in the repository root, this script serves as the primary interface for all STEP-related operations.

### Basic STEP Generation Commands

Generate STEP files from Build123d Python sources using these patterns:

```bash

# Generate from a part definition

python scripts/step path/to/part.py

# Generate from an assembly definition

python scripts/step path/to/assembly.py --kind assembly

# Import an existing STEP file (creates GLB side-car only)

python scripts/step --kind part path/to/imported.step

```

When processing Python files, the CLI creates a sibling `.step` file with the same base name as the source. For assemblies, the `--kind assembly` flag ensures proper handling of compound geometries.

### Custom Output Paths

Control output destinations using either the `-o` flag or the `SOURCE=OUTPUT` syntax for batch operations:

```bash

# Single file with explicit output path

python scripts/step path/to/part.py -o path/to/custom.step

# Multiple files with specific output names

python scripts/step path/to/a.py=out/a.step path/to/b.py=out/b.step

```

After generation, verify artifacts and inspect geometric properties using the inspection tool:

```bash
python scripts/inspect refs path/to/model.step --facts --planes --positioning

```

## Core Implementation Files

The STEP generation pipeline spans multiple packages and languages, coordinated through these key components:

- **[`packages/cadpy/src/cadpy/step_artifact.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadpy/src/cadpy/step_artifact.py)** – The Python implementation that serializes Build123d shapes to STEP format or passes through existing STEP files.

- **`viewer/src/server/step/pythonStepArtifact.mjs`** – Node.js wrapper that orchestrates calls to the Python STEP generator from the server environment.

- **`viewer/src/server/step/stepArtifactCompiler.mjs`** – Core logic determining when STEP artifacts require regeneration and handling error states during compilation.

- **`viewer/src/server/catalog/cadDirectoryScanner.mjs`** – Scans repository directories for STEP sources and registers them in the CAD Viewer catalog, linking generated GLB side-cars for visualization.

- **[`skills/cad/references/step-generation.md`](https://github.com/earthtojake/text-to-cad/blob/main/skills/cad/references/step-generation.md)** – Comprehensive documentation detailing CLI options, workflow patterns, and integration guidelines for the STEP generation system.

## Summary

- **text-to-cad generates STEP files** through the `scripts/step` CLI using the cadpy Python package.
- **Two workflows exist**: generating from Build123d Python sources (requiring a `gen_step()` function) or importing existing STEP/STP files.
- **Assembly support** is available via the `--kind assembly` flag when processing Python definitions.
- **Flexible output options** include automatic sibling placement, explicit `-o` paths, or batch `SOURCE=OUTPUT` syntax.
- **GLB topology artifacts** are automatically generated alongside STEP files to enable CAD Viewer preview and inspection.

## Frequently Asked Questions

### Does text-to-cad require Build123d knowledge to create STEP files?

While generating STEP files from Python sources requires a `gen_step()` function that returns Build123d shapes, you can bypass Python entirely by importing existing STEP or STP files directly. The `python scripts/step --kind part path/to/file.step` command processes legacy CAD files without requiring Build123d code.

### What is the difference between part and assembly generation?

The `--kind` parameter determines how the CLI interprets the source material. Use `--kind part` for single solid geometries and `--kind assembly` when the Python source defines multiple components or compound assemblies. This distinction affects how the STEP file structure is organized and how the CAD Viewer renders the topology.

### Where does text-to-cad store generated STEP files?

By default, the CLI creates STEP files as siblings to their source Python files in the same directory. You can override this behavior using the `-o` flag for single files or the `SOURCE.py=OUTPUT.step` syntax for batch operations, allowing placement in custom directory structures.

### Can I preview STEP files before using them in production?

Yes. The system automatically generates GLB (GL Binary) topology side-car files alongside STEP exports. These lightweight 3D assets enable preview within the CAD Viewer interface. Additionally, the `scripts/inspect` command provides geometric analysis including facts, planes, and positioning data for validation.