DXF parser for node/browser. Not complete at this point but lines, circles and lwpolylines are supported.
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 30
s sections in parsers implementations like circle.js
)
Look at example.js
in the examples/
directory for an example:
examples$ node example.js
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 inbdd unit-testing syntax
(describe
andit
) note that your parsers have to be declared inlib/index.js
(just follow like a monkey the pattern withcircles
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
namedGruntfile.js
:mv gruntfile.js Gruntfile.js
-
Windows:
download nodejs manually from official website
and then run npm install twice (first withmocha
andgrunt
, second time for downloading dependencies)
- run either:
mocha test/*
ORgrunt 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
- the advantage of
npm
is package manager which allows downloading more packages fornodejs
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)
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'
Usage: collector.toSVG('Layer1, Layer2 etc..') You can use '*' for all layers.
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.
Converts the elements that can be converted into SVG path into a single text string path.