Registry / storage / build-dxf

build-dxf

JSON →
library0.1.135jsnpmunverified

A TypeScript library for programmatically building DXF (Drawing Exchange Format) files, suitable for generating CAD drawings in Node.js or browser environments. Latest version 0.1.135 is actively developed with frequent releases. Key differentiators: supports full DXF entities (lines, circles, arcs, text, polylines, blocks), layers, and custom entities; provides a clean builder API; ships with TypeScript definitions; lightweight with no external runtime dependencies. Alternative to complex DXF generators like dxf-writer with a more modern API.

npm install build-dxf
INSTALL
IMPORT
SIG · BUILD-DXF
B
build-dxf
storagejavascriptv0.1.135
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dxf
import dxf from 'build-dxf'
const dxf = require('build-dxf')
Default import, ESM-only. CommonJS require does not work; use dynamic import() if needed.
Drawing
import { Drawing } from 'build-dxf'
Named import for the Drawing class. Both default and named exports exist.
DxfWriter
import { DxfWriter } from 'build-dxf'
Alternative export for the underlying writer. Not typically needed; use Drawing for simpler API.

Demonstrates creating a DXF drawing with lines, circles, text, layers, and saving to a string or file using build-dxf.

import dxf from 'build-dxf'; const drawing = new dxf.Drawing(); // Add entities drawing.addLine({ x1: 0, y1: 0, x2: 100, y2: 0 }); drawing.addCircle({ x: 50, y: 50, r: 20 }); drawing.addText({ x: 10, y: 10, text: 'Hello DXF', height: 5 }); // Add layer drawing.addLayer('myLayer', { color: 1, lineType: 'CONTINUOUS' }); // Set active layer drawing.setActiveLayer('myLayer'); // Generate DXF string const dxfString = drawing.toDxfString(); console.log(dxfString); // Or save to file (Node.js) import { writeFileSync } from 'fs'; writeFileSync('output.dxf', dxfString, 'utf-8');
Debug
Known issues
breakingDrawing.toDxfString() returns a string, not a buffer. In previous versions (pre-0.1.0), it returned a Buffer.
fix
Update code to handle string output, convert to Buffer if needed: Buffer.from(drawing.toDxfString(), 'utf-8')
affects: <0.1.0
deprecatedThe addLayer method signature changed: color is now a number (AutoCAD color index), not a string. Old string colors are deprecated.
fix
Use numeric color values: e.g., 1 for red, 2 for yellow, etc.
affects: >=0.1.0
gotchaCoordinates are always in millimeters. DXF units are not scaled; ensure your values are in mm.
fix
Convert your coordinates to millimeters before passing to build-dxf functions.
affects: all
gotchaText entities require height parameter; if omitted, text may not appear in some viewers.
fix
Always specify height when adding text, e.g., { height: 5 }.
affects: all
gotchaLayer names are case-insensitive in DXF, but build-dxf preserves case. Duplicate layer names with different casing may cause unexpected behavior.
fix
Use consistent casing when adding and switching layers.
affects: all
Errors
Common errors & fixes
TypeError: dxf.Drawing is not a constructor
Using CommonJS require on the default export.
fix
Use ESM import: import dxf from 'build-dxf' or dynamic import: const dxf = await import('build-dxf')
Error: Invalid layer: layerName
Trying to set active layer before adding it.
fix
Add the layer first using drawing.addLayer(layerName, options), then set it active.
TypeError: (dxf_1.default || ...).Drawing is not a function
Incorrect named import usage; probably mixing default and named imports incorrectly.
fix
Use default import: import dxf from 'build-dxf'; then new dxf.Drawing(); or named: import { Drawing } from 'build-dxf'; new Drawing();
Upgrade
Version history
0.1.135latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
node
38
Resources
build-dxf — npm install build-dxf · libregistry