JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 779
  • Score
    100M100P100Q97651F
  • License MIT

JavaScript library for writing DXF files

Package Exports

  • dxf-doc
  • dxf-doc/entities
  • dxf-doc/entities/hatch
  • dxf-doc/entities/hatch.js
  • dxf-doc/entities/index.js
  • dxf-doc/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dxf-doc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dxf-doc

JavaScript library for writing DXF files. The library provides a low-level interface, so basic understanding of the DXF format is not required but can be helpful. The verion of generated DXF files is AC1021 (AutoCAD R2007), so Unicode (UTF-8) is supported

DxfDocument

The class provides the following oprations

  • addHeaderVariables
  • addLayer
  • addLineType
  • addStyle
  • addBlock
  • addEntity/addEntities
  • extents - the shorthand to define drawing extents in the header
  • limits - the shorthand to define drawing limits in the header
  • dxf - returns dxf file content as a string

Supported entity types

  • LINE
  • CIRCLE
  • ELLIPSE
  • ARC
  • LWPOLYLINE
  • TEXT
  • HATCH

Example

const { DxfDocument } = require('dxf-doc');
const { Line, Circle, LwPolyline, Text, Hatch, Ellipse, Arc } = require('dxf-doc/entities');
const { HatchPattern, PolylineBoundaryPath } = require('dxf-doc/entities/hatch');

const fs = require('fs');

// Load patterns from the acad.pat file
const patternLines = fs.readFileSync(__dirname + '/acad.pat')
    .toString()
    .split('\n');
const patterns = HatchPattern.parse(patternLines);
    
const pts = [[150, 10], [160, 60], [190, 70], [190, 10]];

const dxf = new DxfDocument();

dxf.extents([0, 0], [250, 100]);
dxf.limits([0, 0], [250, 100]);

// Add entities
dxf.addEntities(
    new Line(dxf, 10, 10, 70, 70),
    new Circle(dxf, 110, 40, 30),
    new LwPolyline(dxf, pts, true),
    new Hatch(dxf, [
        new PolylineBoundaryPath(pts)
    ], patterns[0]),
    new Text(dxf, 'Hello World!', 5, [200, 50]),
    new Ellipse(dxf, 280, 40, 30, 10, 0.5),
    new Arc(dxf, 360, 40, 30, 0, 270)
);

// Save to file
fs.writeFileSync(__dirname + '/example.dxf', dxf.dxf());

Authors

  • Yuri Spektor

License

MIT - http://rem.mit-license.org