Skip to content

dotoritos-kim/dxf-json

Repository files navigation

DXF-JSON

License: GPL v3

GitHubGitHub Actions

Visual Studio CodeTypeScript

NPM

DXF parser with rich type definitions.

Caution

This is parser is not in stable state yet. Until version 1.0, we may often change name or type of the variables. We're adding rich unit/integration test, but there might be unexpected bug or uncovered situation. Note that official DXF specification is poorly documented, so that many informations are missing and even errors exist. Use your own risk. Thank you for your consideration.

Quick Start

npm i dxf-json # or your loved package manager
import { readFileSync } from 'fs'
import { DxfParser } from 'dxf-json'

const content = readFileSync('foo.dxf', 'utf-8');
const parser = new DxfParser()
const parsedDxf = parser.parseSync(content)

// play with your dxf file
const lwPolylines = parsedDxf.entities.filter(entity => entity.type === 'LWPOLYLINE')

Features

  • Synchronous parsing, asynchronous parsing, and url fetch are possible.
  • Support both ESM and CJS
  • Support TypeScript

Note

We support standard specification of dxf and AutoCAD features only. We're trying our best to support universal dxf files, but we don't support 3rd party specification.

Current Coverage

For dev branch status, see #52

Based on AutoCAD 2024 DXF Reference

  • HEADER Section
  • CLASSES Section
  • TABLES Section
    • APPID
    • BLOCK_RECORD
    • DIMSTYLE
    • LAYER
    • LTYPE
    • STYLE
    • UCS
    • VIEW
    • VPORT
  • BLOCKS Section
  • ENTITIES Section
    • 3DFACE
    • 3DSOLID
    • ACAD_PROXY_ENTITY
    • ARC
    • ATTDEF
    • ATTRIB
    • BODY
    • CIRCLE
    • COORDINATION MODEL
    • DIMENSION
    • ELLIPSE
    • HATCH
    • HELIX
    • IMAGE
    • INSERT
    • LEADER
    • LIGHT
    • LINE
    • LWPOLYLINE
    • MESH
    • MLEADER
    • MLEADERSTYLE
    • MLINE
    • MTEXT
    • OLEFRAME
    • OLE2FRAME
    • POINT
    • POLYLINE
    • RAY
    • REGION
    • SECTION
    • SEQEND
    • SHAPE
    • SOLID
    • SPLINE
    • SUND
    • SURFACE
    • TABLE
    • TEXT
    • TOLERANCE
    • TRACE
    • UNDERLAY
    • VERTEX
    • VIEWPORT
    • WIPEOUT
    • XLINE
  • OBJECTS Section
    • DATATABLE
    • DICTIONARY
    • DICTIONARYVAR
    • DIMASSOC
    • FIELD
    • GEODATA
    • GROUP
    • IDBUFFER
    • IMAGEDEF
    • IMAGEDEF_REACTOR
    • LAYER_FILTER
    • LAYER_INDEX
    • LAYOUT
    • LIGHTLIST
    • MATERIAL
    • MLINESTYLE
    • OBJECT_PTR
    • PLOTSETTINGS
    • RASTERVARIABLES
    • RENDER
    • SECTION
    • SORTENSTABLE
    • SPATIAL_FILTER
    • SPATIAL_INDEX
    • SUNSTUDY
    • TABLESTYLE
    • UNDERLAYDEFINITION
    • VBA_PROJECT
    • VISUALSTYLE
    • WIPEOUTVARIABLES
    • XRECORD
  • THUMBNAILIMAGE Section

Note

The documentation is not ready, but you can check the source code for used types #1 and #2

parseSync

const parser = new DxfParser()
return parser.parseSync(buffer)

parseStream

import fs from 'fs'
const parser = new DxfParser();
const fileStream = fs.createReadStream("dxf file path", { encoding: 'utf8' });
return await parser.parseStream(fileStream);

parseUrl

const parser = new DxfParser();
return await parser.parseFromUrl(url, encoding, RequestInit);

Contribution

See CONTRIBUTING.md

Sponsor this project

 

Contributors 5