# SendCutSend Pre-Upload Validation for DXF and STEP Files

> Enhance your CAD workflow with SendCutSend pre-upload validation for DXF and STEP files. Our system ensures file integrity before manufacturing, saving you time and resources.

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

---

**The text-to-CAD repository implements a two-layer validation system that syntactically validates DXF files on the client side using [`parseDxf.js`](https://github.com/earthtojake/text-to-cad/blob/main/parseDxf.js) and verifies STEP file integrity on the server side through `localAssetBackend.mjs` before any upload to manufacturing services like SendCutSend.**

The open-source text-to-CAD project provides a manufacturing-ready viewer that prepares CAD assets for fabrication workflows. Before any design reaches external cutting services, the codebase enforces strict pre-upload validation through separated client-side parsing and server-side artifact verification pipelines.

## Client-Side DXF Validation Workflow

When a user drops a DXF file into the workbench, the UI validates the asset before any network request is initiated. The file-type selector (`FILE_SHEET_SECTION_IDS.DXF`) immediately routes the payload to the DXF-specific workflow in [`viewer/src/client/components/DxfViewer.js`](https://github.com/earthtojake/text-to-cad/blob/main/viewer/src/client/components/DxfViewer.js).

### Parsing Logic in parseDxf.js

The DXF parser at [`viewer/packages/cadjs/src/lib/dxf/parseDxf.js`](https://github.com/earthtojake/text-to-cad/blob/main/viewer/packages/cadjs/src/lib/dxf/parseDxf.js) scans the raw text for malformed group-code streams, unsupported entities, or inconsistent geometry. When the parser detects structural errors, it throws explicit exceptions with messages such as "DXF group code stream is malformed". This ensures that only syntactically correct DXF data proceeds to the preview engine.

### Error Handling with viewerAlerts.js

The alert system in [`viewer/src/client/workbench/viewerAlerts.js`](https://github.com/earthtojake/text-to-cad/blob/main/viewer/src/client/workbench/viewerAlerts.js) catches parser exceptions and surfaces user-friendly notifications. Users see clear feedback like "DXF load failed" or "DXF 3D preview unavailable" rather than raw stack traces. This client-side gate prevents malformed files from ever consuming server resources.

## Server-Side STEP File Verification

STEP files are handled entirely on the backend because they may be generated from Python scripts or uploaded directly. The validation enforces file-system integrity and artifact generation policies before any manufacturing handoff.

### Extension and Path Validation

The local asset backend (`viewer/src/server/localAssetBackend.mjs`) validates requested STEP paths by checking that the file extension exists within the allowed `STEP_SUFFIXES` set (`.step` or `.stp`). The code confirms that the normalized path exists within the configured CAD Viewer root before proceeding.

### Artifact Compilation Checks

If a STEP artifact is missing, the backend invokes `viewer/src/server/step/stepArtifactCompiler.mjs`. This module verifies that a matching Python generator exists and confirms that the generated STEP file’s hash matches the source. The compiler throws explicit errors such as "STEP artifact generation is not enabled for this CAD Viewer backend" when the backend is not a local filesystem instance.

The API layer in `viewer/src/server/httpHandlers.mjs` translates these backend errors into JSON responses with clear messages like "STEP file is missing." or "STEP artifact generation requires a local filesystem CAD Viewer backend", allowing the client to inform the user before attempting an upload.

## Implementation Examples

To validate a DXF file client-side before SendCutSend upload:

```javascript
import { parseDxf } from '/viewer/packages/cadjs/src/lib/dxf/parseDxf.js';
import { showAlert } from '/viewer/src/client/workbench/viewerAlerts.js';

function validateAndUploadDxf(file) {
  const reader = new FileReader();
  reader.onload = () => {
    try {
      const dxfData = parseDxf(reader.result);
      // If parsing succeeds, proceed to upload
      uploadDxf(file, dxfData);
    } catch (e) {
      // Show a friendly error based on the parser exception
      showAlert('DXF load failed', e.message);
    }
  };
  reader.readAsText(file);
}

```

To trigger STEP artifact generation via the server API:

```bash

# POST request to the STEP generation endpoint

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"file":"myPart/STEP/assembly.step"}' \
  https://viewer.example.com/api/step/generate

```

Server-side extension validation from `localAssetBackend.mjs`:

```javascript
if (!STEP_SUFFIXES.has(extension)) {
  throw new Error('Only STEP/STP sources or same-stem Python generators can generate STEP topology artifacts');
}
if (!fs.existsSync(normalizedRef)) {
  throw new Error(`STEP file not found: ${normalizedRef}`);
}

```

## Summary

- **Client-side DXF validation** occurs in [`parseDxf.js`](https://github.com/earthtojake/text-to-cad/blob/main/parseDxf.js) by scanning for malformed group-code streams, with errors surfaced through [`viewerAlerts.js`](https://github.com/earthtojake/text-to-cad/blob/main/viewerAlerts.js).
- **Server-side STEP validation** enforces file extensions against `STEP_SUFFIXES` and verifies file existence in `localAssetBackend.mjs`.
- **Missing STEP artifacts** trigger the `stepArtifactCompiler.mjs` workflow, which validates Python generators and hash integrity.
- **API error translation** in `httpHandlers.mjs` ensures users receive clear JSON error messages before any manufacturing upload attempt.

## Frequently Asked Questions

### What happens when a DXF file fails client-side validation?

The [`parseDxf.js`](https://github.com/earthtojake/text-to-cad/blob/main/parseDxf.js) parser throws an exception with a specific message like "DXF group code stream is malformed", which [`viewerAlerts.js`](https://github.com/earthtojake/text-to-cad/blob/main/viewerAlerts.js) catches to display a user-friendly "DXF load failed" notification. The file never reaches the server or SendCutSend pipeline.

### Why does STEP validation require a local filesystem backend?

The `stepArtifactCompiler.mjs` module requires direct filesystem access to verify Python generator scripts and write STEP artifacts. When the backend is not a local filesystem instance, the compiler throws "STEP artifact generation is not enabled for this CAD Viewer backend" to prevent invalid generation attempts.

### How does the system handle missing STEP files?

If `localAssetBackend.mjs` cannot locate the requested file, it invokes the artifact compiler to check for a matching Python generator. If generation is possible, the system creates the STEP file and verifies its hash matches the source; otherwise, it returns a "STEP file is missing" JSON error through the HTTP handlers.

### Can the validation workflow be bypassed for testing?

No—the validation layers are enforced at the architecture level. The DXF parser runs immediately on file drop in [`DxfViewer.js`](https://github.com/earthtojake/text-to-cad/blob/main/DxfViewer.js), and STEP routes in `httpHandlers.mjs` always delegate to `localAssetBackend.mjs` for extension and existence checks before any upload proceeds.