DXF parser for node/browser
npm install dxf-mod
, etc. 4.0 introduces the element.
examples/ directory that show how to use the library. There are exposed functions for advanced users, but for the majority of users you can use the Helper object to get the data you're interested in (or convert to SVG):
const helper = new Helper()
// The 1-to-1 object representation of the DXF
console.log('parsed:', helper.parsed)
// Denormalised blocks inserted with transforms applied
console.log('denormalised:', helper.denormalised)
// Create an SVG
console.log('svg:', helper.toSVG())
// Create polylines (e.g. to render in WebGL)
console.log('polylines:', helper.toPolylines())
`
Running the Examples
Node ES5. Will write an SVG to examples/example.es5.svg:
`
$ node examples/example.es5.js
`
Node ES6. Will write an SVG to examples/example.es6.svg:
`
$ npx babel-node examples/example.es6.js
`
Browser. Compile to a browser bundle and open the example webpage:
`
$ npm run compile
$ open examples/dxf.html
`
SVG
Geometric elements are supported, but dimensions, text, hatches and styles (except for line colors) are _not_.
Native SVG elements are used as far as possible for curved entities (, etc.), _except for the SPLINE entity_, which is interpolated.
Here's an example you will find in the functional test output:
!svg example image
Interpolation
The library supports outputting DXFs as interpolated polylines for custom rendering (e.g. WebGL) or other applications, by using:
`
> helper.toPolylines()
`
Command line
There is a command-line utility (courtesy of @Joge97) for converting DXF files to SVG:
`
$ npm i -g dxf
$ dxf-to-svg
Usage: dxf-to-svg [options] [svgFile]
Converts a dxf file to a svg file.
Options:
-V, --version output the version number
-v --verbose Verbose output
-h, --help output usage information
`
Tests
Running
$ npm test
will execute the unit tests.
$ npm run test:functional will run the functional tests in a browser. Please open toSVG.html when the file listing loads in the browser (or open http://localhost:8030/toSVG.html#/`).