-
Notifications
You must be signed in to change notification settings - Fork 405
DxfDocument is null when loading a DXF #29
Comments
The "Load" method will return null if the file has not been able to load. Please verify that the "BICYCLE.dxf" in in the correct place and that your code can see it by using something like this first: This is almost always a local issue involving an incorrect path. I suggest using an exact file path while testing your code so that you know 100% that it works first. Note: |
The file exists and I am able to use the library with many other DXF files but not with bycicle.dxf. Also, the Load method should throw a FileNotFoundException if the file does not exist but it is not the case. Had you the chance to test the file I attached? |
Ahh, I receive a Your issue is that Alternately you are using another unsupported format (Too new?, or from some odd program with bad heders?) |
Thanks. Any chance the Load method can throw System.NotSupportedException in future versions? |
That is a question best asked of the developer haplokuon, but I imagine that there are so many things that can cause the file not to load, and there is very little way to tell between something being unsupported verses something being corrupt etc. You are welcome to investigate and submit a pull request to add the feature, but its easy enough to catch a generic exception or show a generic error to a user whenever the return is null, and just state that it is an unsupported file, and that they should manually resave the file in a newer format (AutoCAD 2007 in my case). Source of the dxf loading ( |
There are two methods in the class DxfDocument exactly for this purpose, called: public static DxfVersion CheckDxfFileVersion(Stream stream, out bool isBinary) and public static DxfVersion CheckDxfFileVersion(string file, out bool isBinary) In your case it will return AutoCad14. netDxf is compatible with dxf versions AutoCad2000 and upwards, anything lower and it will not be able to read it. You can use the Debug build if you want the library to throw any exception that might occur during the reading process. The thing is that, if the file is one of the compatible dxf versions, and the Load method still returns null there is nothing you can do. It might be a bad formatted file or a bug, in that case I will need to take a look at it to find a fix. Daniel |
You can copy all elements to to a compatible dxf file which you can load successfully, then save as it.The new file can be loaded successfully too. |
I got your file " MKM_HdM_EP_100_GR_G00_x_x_01_Grundriss.dxf" and you need to update the library using the latest source code. It seems that the problem you have loading the file is related with a bug while reading the layer states, that has already been fixed. Regarding the reduction in file size that may happen. Overtime the drawing can accumulate a lot of stuff that is not in use anymore like blocks, styles, layers,... If you use AutoCad that exactly the purpose of the "purge" command clean the drawing of unreferenced objects. |
Hi haplokuon. |
@yoonsungkim76 First make sure you use the latest available source code. I found a small problem with your DXF, there are several 1071 codes out of place in the Layer data. If you use the Debug build an assertion (not an exception) will be raised showing that there is something abnormal with your file but will allow you to continue loading it. If you use the Release build the problematic lines will be skipped and the loading process will continue normally without returning null. |
Attached there is a DXF file that is not loaded properly.
DxfDocument dxfLoad = DxfDocument.Load("BICYCLE.dxf");
That line does not throw any exception but dxfLoad is null.
BICYCLE.zip
The text was updated successfully, but these errors were encountered: