tarikjabiri / js-dxf

JavaScript DXF writer
MIT License
179 stars 76 forks source link

Include header and DXF-version (2013) to enable wide usage in dxf viewers #33

Closed kriffe closed 1 year ago

kriffe commented 3 years ago

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):

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)

Testing

kriffe commented 3 years ago

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?

ognjen-petrovic commented 3 years ago

@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.

ognjen-petrovic commented 3 years ago

Switch to TypeScript in version 2?

kriffe commented 3 years ago

@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..)

ognjen-petrovic commented 3 years ago

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.

kriffe commented 3 years ago

First draft of how it could be done https://github.com/kriffe/js-dxf/tree/Minimal-Header

ognjen-petrovic commented 3 years ago

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.

kriffe commented 3 years ago

@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.

kriffe commented 3 years ago

@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.

calebc01 commented 3 years ago

@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.

ognjen-petrovic commented 3 years ago

@calebc01 Here is file: test_hello_world.zip

In LibreCAD it looks like: image

ognjen-petrovic commented 3 years ago

DraftSight says: image

ognjen-petrovic commented 3 years ago

Onshape: image

ognjen-petrovic commented 3 years ago

Catia V5: image

calebc01 commented 3 years ago

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: image

kriffe commented 3 years ago

@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.

single_line.zip

kriffe commented 3 years ago

@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 commented 3 years ago

@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.

single_line.zip

@kriffe - the single line imports into Fusion 360 without any issues. It does not work in Illustrator, however.

ognjen-petrovic commented 3 years ago

@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...