This project has moved. For the latest updates, please go here.

Handling Unknown Sections of DXF

Nov 1, 2013 at 1:22 PM
Hi,

I tried using your code against some dxf files we were supplied by a customer.

They seemed to contain a section that was not handled by the code very well. Basically the stringcode pair that define the section were not recognised. to get round this I added a little bit of code to handle this better. The changes I made were.

In Read method:

while (dxfPairInfo.Value != StringCode.EndOfFile)
        {
            if (dxfPairInfo.Value == StringCode.BeginSection)
            {
                dxfPairInfo = this.ReadCodePair();
                switch (dxfPairInfo.Value)
                {
                    case StringCode.HeaderSection:
                        this.ReadHeader();
                        break;
                    case StringCode.ClassesSection:
                        this.ReadClasses();
                        break;
                    case StringCode.TablesSection:
                        this.ReadTables();
                        break;
                    case StringCode.BlocksSection:
                        this.ReadBlocks();
                        break;
                    case StringCode.EntitiesSection:
                        this.ReadEntities();
                        break;
                    case StringCode.ObjectsSection:
                        this.ReadObjects();
                        break;

                     default:
                        this.ReadUknownSection();
                        break;

                        //throw new InvalidDxfSectionException(dxfPairInfo.Value, "Unknown section " + dxfPairInfo.Value + ".");
                }
            }
            dxfPairInfo = this.ReadCodePair();
        }
This points to this method:

private void ReadUknownSection()
    {
         dxfPairInfo = this.ReadCodePair();
        while (dxfPairInfo.Value != StringCode.EndSection)
        {
            dxfPairInfo = this.ReadCodePair();
        }
    }
Its quite simple as it basically skips though the unknown section, but it meant I could continue to read the file without an exception. it could maybe be switched so that the user can control if it skips unknown sections or exceptions?

I wondered if it might be a useful addition to the library?

Thanks

Thanks
Coordinator
Nov 1, 2013 at 8:02 PM
Yes, I am aware of this bug. The problem has to do with dxf files that contains the optional THUMBNAILIMAGE section. In a couple days I will update the code with a fix for this bug and a few more.

Daniel