1

Closed

DxfDocument.load returns null

description

why would the load method return null, I have a file that imports into autocad, but returns null through the load command, is it possible to validate the file in any way?

file attachments

Closed May 11 at 6:38 PM by haplokuon

comments

mawarnes_codeplex wrote Apr 13 at 7:22 PM

Having run the file through the test project I got the following output

THE FILE AbbeyXls.dxf IS NOT A SUPPORTED DXF

FILE VERSION: AutoCad14

brilliant work, thank you very much

mawarnes_codeplex wrote Apr 13 at 7:37 PM

In case it helps anyone else, I manually changed the version string in the dxf file line 8 from AC1014 to AC1015 then the file imported! brilliant!

haplokuon wrote Apr 20 at 6:05 PM

The dxf format is a kinda loose format, it lacks a well defined structure. Years ago they introduced, between other things, what is called subclass markers to segment the different properties of every entity, table,... I know that the 2000 version and upwards requires them, but perhaps those changes were introduced even earlier. The 2000 is old enough so any program that works with dxf should be able to read and write them without problems, so I decided to set the limit there.

So if your file has those updates the change you made will work, since the file version is defined by that string.

I will check and run a few tests and if those changes where introduce earlier than I thought I will lower the supported version to v14 or even v13. What I am sure is that v12 will not work.

Daniel

rms80 wrote Apr 28 at 2:21 AM

Here is a bit of code that will read in the text and rewrite the version string, resolved this problem for me (thanks for netDXF it is fantastic):
            bool bIsBinary = false;
            netDxf.Header.DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file_path, out bIsBinary);
            if ((int)dxfVersion < (int)netDxf.Header.DxfVersion.AutoCad2000) {
                string fileData = File.ReadAllText(sDXFPath);
                string versionString = "";
                if (dxfVersion == netDxf.Header.DxfVersion.AutoCad14)
                    versionString = "AC1014";
                else if (dxfVersion == netDxf.Header.DxfVersion.AutoCad13)
                    versionString = "AC1012";
                fileData = fileData.Replace(versionString, "AC1015");
                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(fileData));
                dxfFile = DxfDocument.Load(stream);

haplokuon wrote Apr 28 at 5:54 PM

I cannot guarantee that loading v14 dxf files will always work. Now, AutoCad doesn't even allow to save v13 or v14 dxfs, so it is hard to test it without a proper file. Those versions are 20 years old, and I am not sure if it is worth the effort to make them work.

Daniel