js-dxf
js-dxf copied to clipboard
Include header and DXF-version (2013) to enable wide usage in dxf viewers
To be able to use generated accurate DXF-files in more than LibreCAD there is a need to include a minimal version of the DXF header (not so small thou..) that specifies both version and default data needed.
This will have the following effects (positive and negative):
- Splines and other advanced features can be generated
- DXF Viewers know what version of the protocol is beeing used
- A simple Hello world dxf file will go from 1 kb to ~65 kb (if Dictionary / Tables isnt compressed somehow..)
If this is desirable for the js-dxf repo the following changes is most likely needed (based on previous implementation I have done in other projects)
- [x] Create a Header class to contain all information
- [x] Lock $ACADVER to version AC1027 (2013)
- [x] Increase $HANDSEED header value with every added feature call (this.handSeed++ in Drawing class methods) https://forums.autodesk.com/t5/objectarx/how-to-handle-handseed-in-a-generated-dxf-file/td-p/2670668
- [x] Include minimal lists with default values of Tables, Blocks and Dictionary (dictionary the trickiest..)
- [x] Include UUID (something like https://www.npmjs.com/package/uuid) dependency for unique $FINGERPRINTGUID in every generated file
- [ ] Handle different units ($INSUNITS might not be enough. Please see comments in https://github.com/ognjen-petrovic/js-dxf/blob/v2-master/src/Header.js#L164)
- [ ] Convert to Typescript (wait on stable js solution)
- [ ] Update tests and spec. files
Testing
- [x] Hello World working in eDrawings, QCad
- [x] Hello World working in LibreCAD
- [ ] Hello World working in AutoCAD (can anyone test?)
- [ ] Polylines and Arcs working in eDrawings, QCad,
- [ ] Polylines and Arcs working in LibreCAD
- [ ] Polylines and Arcs working in AutoCAD
- [ ] Face3D and Polylines3D working in eDrawings, QCad
- [ ] Face3D and Polylines3D working in LibreCAD
- [ ] Face3D and Polylines3D working in AutoCAD
I have a lot of example code to solve all this, based on some of my other projects with dxf exporters. But since the suggested changes might have a big impact on this repository I want to make sure that this is something that is desirable before I contribute with that source code.
The biggest issue is the version jump to 2013 (might need jump to major 2.X for repo) and the huge increase in size for small dxf files (unless someone is more successful than me in minimizing all that default data..)
@ognjen-petrovic What are your thoughts?
@kriffe I like your idea about version 2. Yes, the size of generated file is going to increase but that is the price of progress. Version 1 will remain available.
Switch to TypeScript in version 2?
@ognjen-petrovic That is a good idea. Lots of benefits from typescript. Maybe we get it working with header first and then convert before release (not good to do 2 things at the same time..)
Maybe we get it working with header first and then convert before release (not good to do 2 things at the same time..)
Sure, I agree.
First draft of how it could be done https://github.com/kriffe/js-dxf/tree/Minimal-Header
First draft of how it could be done https://github.com/kriffe/js-dxf/tree/Minimal-Header
Great! Thanks. I took a look...I have not worked for a while at DXFs and must again catch grasp on sections, blocks.. :) I made some small changes/additions, will create a PR shortly.
@ognjen-petrovic : The way the standard is created is horrible.. I think a lot of the information is redundant, but since some viewers (specifically AutoCAD) are very strict its very time consuming to reduce to the absolute minimal.
I have now a working version for the Hello World example. Still some work with testing other entities and cleaning up, but worked out pretty much as I hoped.
@ognjen-petrovic I simplifyed the header some more and created a draft PR to your side also. Not sure which branch is best to work from.
@kriffe - I can test in Fusion360, QCAD, and Illustrator. Fusion360 is by Autodesk, and it may or may not use the same DXF interpreter that AutoCAD does.
DraftSight says:
Onshape:
Catia V5:
On import into Fusion 360, I get an error: "Failed to insert this DXF file." Fusion 360 does not provide any additional information, unfortunately.
Illustrator also errors out, "The file "test_hello_world.dxf is in an unknown format and cannot be opened."
QCAD appears to work, but QCAD historically does the best it can and ignores errors:
@calebc01 Could you make another test with a file containing just a basic line (see attached)?
If this works we can narrow the issue down to some Entity, the setting of Unit or Layer. If this does not work its something more general with the header.
@ognjen-petrovic Seems like the line style was not preserved for the others. Perhaps we need to add the following to the Defalt Tables under generateLtypeTable() (https://github.com/ognjen-petrovic/js-dxf/blob/v2-master/src/DefaultTables.js#L212)
0
LTYPE
72
65
70
64
2
DASHED
3
_ _ _
73
2
40
10
49
5
49
-5
0
LTYPE
72
65
70
64
2
DOTTED
3
. . .
73
2
40
5
49
0
49
-5
0
LTYPE
72
65
70
64
2
DASHDOT
3
_ . _
73
4
40
1.5
49
0.5
49
-0.5
49
0
49
-0.5
@calebc01 Could you make another test with a file containing just a basic line (see attached)?
If this works we can narrow the issue down to some Entity, the setting of Unit or Layer. If this does not work its something more general with the header.
@kriffe - the single line imports into Fusion 360 without any issues. It does not work in Illustrator, however.
@ognjen-petrovic Seems like the line style was not preserved for the others. Perhaps we need to add the following to the Defalt Tables under generateLtypeTable() (https://github.com/ognjen-petrovic/js-dxf/blob/v2-master/src/DefaultTables.js#L212)
Yes I see, I'm going to add other types...