libdxfrw icon indicating copy to clipboard operation
libdxfrw copied to clipboard

DXF file generated by running dwg2dxf cannot be opened by AutoCAD

Open cqwuxiaolong opened this issue 4 years ago • 11 comments

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.

cqwuxiaolong avatar Dec 01 '20 15:12 cqwuxiaolong

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

lordofbikes avatar Jan 10 '21 23:01 lordofbikes

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

Guruprasad-Rane avatar May 21 '21 19:05 Guruprasad-Rane

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

lordofbikes avatar May 22 '21 14:05 lordofbikes

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

Guruprasad-Rane avatar May 23 '21 16:05 Guruprasad-Rane

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.

UnfinishedBusiness avatar Oct 25 '21 17:10 UnfinishedBusiness

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: <Invalid>, Replaced by: <Set to Null>

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 avatar Jan 26 '22 19:01 ferrellsl

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 avatar Jan 26 '22 19:01 ferrellsl

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

ferrellsl avatar Jan 26 '22 20:01 ferrellsl

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?

zxcv8553172 avatar Jun 05 '24 10:06 zxcv8553172

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.

lordofbikes avatar Jun 05 '24 11:06 lordofbikes

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.

zxcv8553172 avatar Jun 06 '24 01:06 zxcv8553172