Skip to content

LiamKarlMitchell/dxf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dxf

DXF parser for node/browser. Not complete at this point but lines, circles and lwpolylines are supported.

Architecture

Parsing DXF is in fact very simple, since dxf files are expressed in plain text. What this parser do is only it iterates in appropriate manner through whole dxf file and whenever it encounters interesting data (every entry in dxf format has its, let's say class - you can observe existance of dxf's classes in e.g. case 30s sections in parsers implementations like circle.js)

Running

Look at example.js in the examples/ directory for an example:

examples$ node example.js

Developing your own types

In order to develop your own types you might follow this procedure:

  • create simple .dxf file using LibreCad

  • add some lines, points (or whatever) using LibreCad

  • create new parser in similar manner like circle.js is

  • look at some examples in test/entities.js, then create new entries in bdd unit-testing syntax (describe and it) note that your parsers have to be declared in lib/index.js (just follow like a monkey the pattern with circles and other types)

  • install appropriate tools with following commands:

    • Ubuntu:
     which nodejs npm || sudo apt-get install nodejs npm            # install nodejs npm is does not exist in the system
     sudo npm install -g mocha grunt                                # install *globally* mocha and grunt
     ls lib/handlers && npm install || echo cd to dxf project first # this installs packages required by this `dxf` parser listed in `package.json`
                                                                    # this line is only for easier copy&paste
    

    Tip: on Linux, it is better to have gruntfile.js named Gruntfile.js:

     mv gruntfile.js Gruntfile.js
    
    • Windows:

      download nodejs manually from official website
      and then run npm install twice (first with mocha and grunt, second time for downloading dependencies)

  • run either: mocha test/* OR grunt watch (grunt watch --gruntfile gruntflie.js)
    • the advantage of grunt watch is that whenever you will modify any of project files the project will be automatically executed
    • but you can also execute mocha manually every time

Tools

  • npm is package manager which allows downloading more packages for nodejs
  • mocha is testing framework (this tool allows you veryfing that every parser works as expected for various .dxf)
  • grunt is tool allowing you, in between, making building process less effort-consuming (e.g. when file is changed, it automatically re-executes processes)

DXF in the browser

It is possible to build this module with Browserify Assuming your current working directory is the repo root and you want to expose it globally. browserify dxf/lib --outfile dxf.js -s dxf

If you don't want to pollute the global namespace dont' use -s dxf

A way to prepare script every 1sec useful when developing. watch -n1 'browserify dxf/lib --outfile dxf.js -s dxf'

SVG Functions

Usage: collector.toSVG('Layer1, Layer2 etc..') You can use '*' for all layers.

toSVG

There is now a toSVG method, simply give a list of layers that you want to convert to an SVG and anything that can and has been implemented with a toSVG method will be turned into SVG data.

Will return a string.

toSVGPath

Converts the elements that can be converted into SVG path into a single text string path.

About

DXF parser for node/browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • JavaScript 100.0%