haplokuon / netDxf

.net dxf Reader-Writer
MIT License
1.01k stars 411 forks source link

Weird line type issue keeping dxf from being opened #317

Closed donnyv closed 2 years ago

donnyv commented 3 years ago

Attached are 2 dxf files. They are exactly the same except the line type on layer V-PROP-ASSESS has been changed to HIDDEN. For some reason when the line type is set to Wetlands. netDxf will not open it. I tried comparing the dxf file contents but its hard to make heads or tails out of that format.

LineTypeRemovedFor_V-PROP-ASSESS.zip

haplokuon commented 3 years ago

Your DXF files contains a lot of external referenced stuff. In your case, on my side, your file "0910_029_org.dxf" is the one giving me problems because it cannot find a required shape file. I may add a workaround for that, but I had no problems with the other file "0910_029_linetypechanged.dxf".

Try the latest code and the release build if you have not done so, yet.

donnyv commented 3 years ago

0910_029_org.dxf is the one I had issues with. I'm using the latest release.

haplokuon commented 3 years ago

I found a couple problems that will be fixed with the next update, that may affect your file. One has to do with getting the information from the SHX file through the ShapeStyle class. The other one is related with linetypes defined in the layer states not found in the document linetype list, in your case due to the externally referenced drawings.

Remember that when using shapes in complex linetypes or as entities, you need to supply a way to find the SHX file, like: DxfDocument dxf = DxfDocument.Load(file, new List<string> {@".\Support"});

donnyv commented 3 years ago

Unfortunately I don't have control of the drawing. I get them however they send it. I only need the actual line work in it. Thank you so much for looking at it.

donnyv commented 3 years ago

I just ran across another dxf with the same issue but different layers. It could help you with testing. 0909_021.zip

haplokuon commented 3 years ago

Found an invalid handle to a linetype in a LayerState. I should have safely cast that reference, I do not do it everywhere, and this kind of wrong values appear from time to time. The program should be responsible of writing correct values in the required fields, nonetheless, but if AutoCad does not complain, me neither, usually it crashes with bad handle references. It is a very easy fix, if you want to try it change the line 11114 of the DxfReader.cs where it says

Linetype linetype = (Linetype) this.doc.GetObjectByHandle((string) recordEntry.Value);

should say

Linetype linetype = this.doc.GetObjectByHandle((string) recordEntry.Value) as Linetype;
donnyv commented 3 years ago

Funny thing is that this dxf came from a AutoCad export.