LibreCAD / libdxfrw

Successor of https://sourceforge.net/projects/libdxfrw/, developed for LibreCAD, by LibreCAD Contributors, usable for all
GNU General Public License v2.0
187 stars 71 forks source link

DXF file generated by running dwg2dxf cannot be opened by AutoCAD #19

Open cqwuxiaolong opened 3 years ago

cqwuxiaolong commented 3 years ago

I use AutoCAD to draw a random drawing and save it as DWG. The DXF file generated by running DWG 2dxf cannot be opened by AutoCAD. If you open it with notpad + +, you will see a lot of black "NUL". There is no such "NUL" in DXF generated by AutoCAD.

lordofbikes commented 3 years ago

Can you share these files please? When you pack them into a ZIP archive, you can paste it here.

Guruprasad-Rane commented 3 years ago

Faced similar problem. DXF file generated by libdxfrw can not be opened in XED text editor. This is due to NULL characters at some places. dwg2dxf.tar.gz

This issue can was solved by adding t=t.c_str(); in the following function in dxfwritter.cpp I am not sure whether it is a correct approach but it removed thee trailing NULL character.

bool dxfWriter::writeUtf8String(int code, std::string text) {
    std::string t = encoder.fromUtf8(text);
    t = t.c_str();
    return writeString(code, t);
}

dwg2dxf after fixing.tar.gz

lordofbikes commented 3 years ago

@Guruprasad-Rane this issue is about dwg2dxf, did you also use it when the problem happened to you? From my understanding dwg2dxf is not a ready to use file converter, it is more an example for how to use libdxfrw. As this doesn't happen in LibreCAD 2/3, I must assume an issue in dwg2dxf or it uses functionality which is not used by LibreCAD. Anyhow, when the example is buggy, we should solve it. Many thanks @Guruprasad-Rane for pointing out a solution. I have to take a look into sources to understand the issue and evaluate if your solution is appropriate.

Guruprasad-Rane commented 3 years ago

@lordofbikes Yes, I was using dwg2dxf when this issue happen.

UnfinishedBusiness commented 2 years ago

Does anyone know why this is? I'm using libdxfrw to export DXF files. The DXF files that are exported are opening fine in LightBurn, SheetCAM, and most online tools but they will not open in any Autodesk products. Fusion simply says failed to open DXF file or something similar to this without any useful explanation.

ferrellsl commented 2 years ago

I have the same problem. The DXF files generated with dwg2dxf open without issue using ProgeCAD and other apps, but fail to load with AutoCAD. I'm using version AutoCAD 2020. When I audit the DXFs in ProgeCAD, ProgeCAD reports the following issue but still loads the file without any other complaints: AcDbLayerTableRecord(10), PlotStyleName Id (F), Validation: , Replaced by: \

Not sure if the above info is what's causing the AutoCAD load failure or not. I've also attempted to use AutoCAD's recover command on the DXF files but the recover command fails without any error messages at all.

ferrellsl commented 2 years ago

I seem to have found a fix. Since AutoCAD's recover command was failing I decided to use the CLASSICINSERT command to see what errors were produced. CLASSICINSERT complained about the $HANDSEED value of 20000 being too low and to edit the file and change the value to 20001. I did this a few times and each successive insert failed with the same message and to add another 1 to the handseed value. So, I decided to change the handseed value to something enormous and it worked. I just added an additional zero to the value making it 200000 and it now loads.

ferrellsl commented 2 years ago

I just confirmed that editing line 913 of drw_header.cpp and changing the value to 200000 eliminates the AutoCAD load problem for me.

CLASSICINSERT now works without any issues.

Edited line should read: writer->writeString(5, "XXXXXX");

Replace the X's with the hex number that you want to use. Make sure it's the same size as the number of entities in your DXF file or slightly larger and then recompile. Another option is to just edit your DXF file and change the handseed value there and save it.

Ideally, this library and/or the dwg2dxf program should calculate the correct handseed value for the user rather than using an arbitrary, hardcoded value of 20000 hex (131,072 decimal).

zxcv8553172 commented 3 months ago

I have the same problem,too. autoCAD2020 and autoCAD2007 can't open dwg2dxf or dxf2dxf that autoCAD tell me Press Enter continue. If press Enter, my dxf file is close. Who can solve this problem?

lordofbikes commented 3 months ago

As already mentioned, this can't be solved without a sample to reproduce the issue. That means the DWG and converted DXF files. Also the reasons for failing in AutoCAD can be various, it is not necessary the same cause. From Autodesk TrueView I know, that there is an error message, usually showing a line number and explaining the issue. The message is in the output panel, where the Press Enter prompt appear, it can be expanded and scrolled.

zxcv8553172 commented 3 months ago

As already mentioned, this can't be solved without a sample to reproduce the issue. That means the DWG and converted DXF files. Also the reasons for failing in AutoCAD can be various, it is not necessary the same cause. From Autodesk TrueView I know, that there is an error message, usually showing a line number and explaining the issue. The message is in the output panel, where the Press Enter prompt appear, it can be expanded and scrolled.

A sample I give you, errorDxf2Dxf.zip autoCAD tell me Error in APPID Table.