diff --git a/ACadSharp.Examples/IOExamples.cs b/ACadSharp.Examples/IOExamples.cs deleted file mode 100644 index 26cae2e7..00000000 --- a/ACadSharp.Examples/IOExamples.cs +++ /dev/null @@ -1,44 +0,0 @@ -using ACadSharp.IO; -using System.Collections.Generic; - -namespace ACadSharp.Examples -{ - /// - /// Examples of conversion and saving documents - /// - public class IOExamples - { - /// - /// Read a dwg and save the entities in a new file - /// - /// - /// - public void DwgEntitiesToNewFile(string input, string output) - { - /* --- ATENTION --- - * ACadSharp cannot write a readed dwg/dxf file due a problem in the file structure when the dxf is writen - * the workaround for now is to move the entities and save them in a new file - */ - CadDocument doc = DwgReader.Read(input); - - //New document to transfer the entities - CadDocument transfer = new CadDocument(); - doc.Header.Version = doc.Header.Version; - - //Nove the entities to the created document - List entities = new List(doc.Entities); - foreach (var item in entities) - { - ACadSharp.Entities.Entity e = doc.Entities.Remove(item); - transfer.Entities.Add(e); - } - - //Save the document - using (DxfWriter writer = new DxfWriter(output, doc, false)) - { - writer.OnNotification += Common.NotificationHelper.LogConsoleNotification; - writer.Write(); - } - } - } -} diff --git a/ACadSharp.Examples/ReaderExamples.cs b/ACadSharp.Examples/ReaderExamples.cs index 1b9c5165..f5cda469 100644 --- a/ACadSharp.Examples/ReaderExamples.cs +++ b/ACadSharp.Examples/ReaderExamples.cs @@ -1,5 +1,7 @@ -using ACadSharp.Examples.Common; +using ACadSharp.Entities; +using ACadSharp.Examples.Common; using ACadSharp.IO; +using System.Collections.Generic; namespace ACadSharp.Examples { @@ -30,5 +32,36 @@ public static void ReadDwg(string file) CadDocument doc = reader.Read(); } } + + /// + /// Read the entities section from a dxf file and add them to a + /// + /// + public static void ReadEntitiesFromDxf(string file) + { + CadDocument doc = new CadDocument(); + List entities = new List(); + + using (DxfReader reader = new DxfReader(file)) + { + reader.OnNotification += NotificationHelper.LogConsoleNotification; + entities = reader.ReadEntities(); + } + + doc.Entities.AddRange(entities); + } + + /// + /// Read the tables section from a dxf file. + /// + /// + public static void ReadTablesFromDxf(string file) + { + using (DxfReader reader = new DxfReader(file)) + { + reader.OnNotification += NotificationHelper.LogConsoleNotification; + CadDocument doc = reader.ReadTables(); + } + } } }