TypeScript library to read and write AutoCAD DWG and DXF files. Ported from the C# ACadSharp library.
- Read/Write DXF files (ASCII and binary)
- Read/Write DWG files
- Extract and modify geometric entities (lines, arcs, circles, polylines, dimensions, etc.)
- Manage table entries (blocks, layers, line types, text styles, dimension styles)
- Convert CAD documents to SVG
- Full TypeScript type definitions
| DxfReader | DxfWriter | DwgReader | DwgWriter | |
|---|---|---|---|---|
| AC1009 | ✔️ | ❌ | ❌ | ❌ |
| AC1012 | ✔️ | ✔️ | ❌ | ❌ |
| AC1014 | ✔️ | ✔️ | ✔️ | ✔️ |
| AC1015 | ✔️ | ✔️ | ✔️ | ✔️ |
| AC1018 | ✔️ | ✔️ | ✔️ | ✔️ |
| AC1021 | ✔️ | ✔️ | ✔️ | ❌ |
| AC1024 | ✔️ | ✔️ | ✔️ | ✔️ |
| AC1027 | ✔️ | ✔️ | ✔️ | ✔️ |
| AC1032 | ✔️ | ✔️ | ✔️ | ✔️ |
npm install @node-projects/acad-tsimport fs from 'fs';
import { DwgReader } from '@node-projects/acad-ts';
const buffer = fs.readFileSync('drawing.dwg');
const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
const doc = DwgReader.ReadFromStream(arrayBuffer, (sender, e) => {
console.log(e.Message);
});
// Access entities in model space
for (const entity of doc.modelSpace.entities) {
console.log(entity.constructor.name, entity.handle);
}import fs from 'fs';
import { DxfReader } from '@node-projects/acad-ts';
const buffer = fs.readFileSync('drawing.dxf');
const data = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
const doc = DxfReader.ReadFromStream(data, (sender, e) => {
console.log(e.Message);
});import fs from 'fs';
import { CadDocument, DwgWriter, ACadVersion, Line, XYZ } from '@node-projects/acad-ts';
const doc = new CadDocument();
doc.header.version = ACadVersion.AC1032;
const line = new Line();
line.startPoint = new XYZ(0, 0, 0);
line.endPoint = new XYZ(100, 100, 0);
doc.modelSpace.addEntity(line);
const buffer = new ArrayBuffer(0);
DwgWriter.WriteToStream(buffer, doc);import { CadDocument, DxfWriter } from '@node-projects/acad-ts';
const doc = new CadDocument();
// ... add entities ...
const output = new Uint8Array(1024 * 1024);
const writer = new DxfWriter(output, doc);
writer.Write();import { SvgWriter } from '@node-projects/acad-ts';
const output = new Uint8Array(1024 * 1024);
const svgWriter = new SvgWriter(output, doc);
svgWriter.Write();import { CadDocument, Layer, Line, Circle, XYZ, Color } from '@node-projects/acad-ts';
const doc = new CadDocument();
// Create a layer
const layer = new Layer();
layer.name = 'MyLayer';
layer.color = Color.fromColorIndex(1); // Red
doc.layers.add(layer);
// Add a line
const line = new Line();
line.startPoint = new XYZ(0, 0, 0);
line.endPoint = new XYZ(10, 5, 0);
line.layer = layer;
doc.modelSpace.addEntity(line);
// Add a circle
const circle = new Circle();
circle.center = new XYZ(5, 5, 0);
circle.radius = 3;
doc.modelSpace.addEntity(circle);npm install
npm run buildThe compiled output will be in the dist/ directory.
npm testSee the docs folder for detailed documentation on specific topics:
- CadDocument - Document structure and collections
- CadObject - Base object properties
- Entities - Working with geometric entities
- Tables - Table entries (layers, line types, styles)
- Block Records - Blocks and block records
- Inserts - Block insertions
- Dimensions - Dimension entities
- Non-Graphical Objects - Layouts, dictionaries, etc.
- Reading files - Reader configuration and usage
- Writing files - Writer configuration and usage