public void NotAllowDuplicate() { Line line = new Line(); CadDocument doc = new CadDocument(); doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line); Assert.Throws <ArgumentException>(() => doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line)); }
/// <inheritdoc/> public override CadDocument Read() { this._document = new CadDocument(false); this._builder = new DxfDocumentBuilder(this._document, this.OnNotificationHandler); this._reader = this._reader ?? this.getReader(); while (this._reader.LastValueAsString != DxfFileToken.EndOfFile) { if (this._reader.LastValueAsString != DxfFileToken.BeginSection) { this._reader.ReadNext(); continue; } else { this._reader.ReadNext(); } switch (this._reader.LastValueAsString) { case DxfFileToken.HeaderSection: this._document.Header = this.ReadHeader(); break; case DxfFileToken.ClassesSection: this._document.Classes = this.readClasses(); break; case DxfFileToken.TablesSection: this.readTables(); break; case DxfFileToken.BlocksSection: this.readBlocks(); break; case DxfFileToken.EntitiesSection: this.readEntities(); break; case DxfFileToken.ObjectsSection: this.readObjects(); break; default: this.OnNotificationHandler(this, new NotificationEventArgs($"Section not implemented {this._reader.LastValueAsString}")); break; } this._reader.ReadNext(); } this._builder.BuildDocument(); return(this._document); }
static IEnumerable <Insert> getInsertEntities(string file, string blockname) { CadDocument doc = DwgReader.Read(file); // Get the model space where all the drawing entities are BlockRecord modelSpace = doc.BlockRecords["*Model_Space"]; // Get the insert instance that is using the block that you are looking for return(modelSpace.Entities.OfType <Insert>().Where(e => e.Block.Name == blockname)); }
/// <summary> /// Read a dxf document in a stream /// </summary> /// <param name="stream"></param> /// <param name="notification">Notification handler, sends any message or notification about the reading process.</param> /// <returns></returns> public static CadDocument Read(Stream stream, NotificationEventHandler notification = null) { CadDocument doc = null; using (DxfReader reader = new DxfReader(stream, notification)) { doc = reader.Read(); } return(doc); }
/// <summary> /// Read the complete document. /// </summary> public CadDocument Read() { CadDocument doc = new CadDocument(); doc.Header = ReadHeader(); doc.Classes = ReadClasses(); ReadTables(doc); ReadEntities(doc); return(doc); }
public static void AssertTableHirearchy(CadDocument doc) { //Assert all the tables in the doc assertTable(doc, doc.AppIds); assertTable(doc, doc.BlockRecords); assertTable(doc, doc.DimensionStyles); assertTable(doc, doc.Layers); assertTable(doc, doc.LineTypes); assertTable(doc, doc.TextStyles); assertTable(doc, doc.UCSs); assertTable(doc, doc.Views); assertTable(doc, doc.VPorts); }
/// <summary> /// Read the ENTITIES section of the DXF file. /// </summary> public void ReadEntities(CadDocument document) { //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-7D07C886-FD1D-4A0C-A7AB-B4D21F18E484 //Get the needed handler m_reader = getSectionHandler(DxfFileToken.EntitiesSection); //Advance to the first value in the section m_reader.ReadNext(); //Loop until the section ends while (!m_reader.EndSectionFound) { document.AddEntity(readEntity()); } }
public static void AssertBlockRecords(CadDocument doc) { foreach (BlockRecord br in doc.BlockRecords) { Assert.Equal(br.Name, br.BlockEntity.Name); documentObjectNotNull(doc, br.BlockEntity); documentObjectNotNull(doc, br.BlockEnd); foreach (Entities.Entity e in br.Entities) { documentObjectNotNull(doc, e); } } }
public void AddCadObject() { Line line = new Line(); CadDocument doc = new CadDocument(); doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line); CadObject l = doc.GetCadObject(line.Handle); //Assert existing element Assert.NotNull(l); Assert.Equal(line, l); Assert.False(0 == l.Handle); Assert.Equal(line.Handle, l.Handle); }
static void ReadDwg() { string[] files = Directory.GetFiles(PathSamples + "/dwg/", "*.dwg"); foreach (var f in files) { using (DwgReader reader = new DwgReader(f, onNotification)) { CadDocument doc = reader.Read(); } Console.WriteLine($"file read : {f}"); Console.ReadLine(); } }
static void ReadDwg() { //string file = Path.Combine(PathSamples, "dwg/drawing_2000.dwg"); //string file = Path.Combine(PathSamples, "dwg/drawing_2007.dwg"); //string file = Path.Combine(PathSamples, "dwg/drawing_2010.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_R14.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2000.dwg"); string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2007.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2010.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2013.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2018.dwg"); using (DwgReader reader = new DwgReader(file)) { CadDocument doc = reader.Read(onProgress); } }
public static void AssertDocumentDefaults(CadDocument doc) { //Assert the default values for the document entryNotNull(doc.BlockRecords, "*Model_Space"); entryNotNull(doc.BlockRecords, "*Paper_Space"); entryNotNull(doc.LineTypes, "ByLayer"); entryNotNull(doc.LineTypes, "ByBlock"); entryNotNull(doc.LineTypes, "Continuous"); entryNotNull(doc.Layers, "0"); entryNotNull(doc.TextStyles, "Standard"); entryNotNull(doc.AppIds, "ACAD"); entryNotNull(doc.DimensionStyles, "Standard"); entryNotNull(doc.VPorts, "*Active"); notNull(doc.Layouts.FirstOrDefault(l => l.Name == "Model"), "Model"); }
private static void assertTable <T>(CadDocument doc, Table <T> table) where T : TableEntry { Assert.NotNull(table); notNull(table.Document, $"Document not assigned to table {table}"); Assert.Equal(doc, table.Document); Assert.Equal(doc, table.Owner); Assert.True(table.Handle != 0); CadObject t = doc.GetCadObject(table.Handle); Assert.Equal(t, table); foreach (T entry in table) { Assert.Equal(entry.Owner.Handle, table.Handle); Assert.Equal(entry.Owner, table); documentObjectNotNull(doc, entry); } }
/// <summary> /// Read the TABLES section of the DXF file. /// </summary> /// <param name="document">Document where the tables reside.</param> public void ReadTables(CadDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-A9FD9590-C97B-4E41-9F26-BD82C34A4F9F //Get the needed handler m_reader = getSectionHandler(DxfFileToken.TablesSection); //Advance to the first value in the section m_reader.ReadNext(); //Loop until the section ends while (!m_reader.EndSectionFound) { readTable(document); if (m_reader.LastValueAsString == DxfFileToken.EndTable) { m_reader.ReadNext(); } } }
public DxfDocumentBuilder(CadDocument document, NotificationEventHandler notification = null) : base(document, notification) { }
internal AppIdsTable(CadDocument document) : base(document) { }
public void ReadCrcEnabledTest(string test) { DwgReaderFlags flags = DwgReaderFlags.CheckCrc; CadDocument doc = DwgReader.Read(test, flags, this.onNotification); }
internal DimensionStylesTable(CadDocument document) : base(document) { }
protected Table(CadDocument document) { this.Owner = document; document.RegisterCollection(this); }
internal LineTypesTable(CadDocument document) : base(document) { }
public static void AssertDocumentTree(CadDocument doc) { CadDocumentTree tree = System.Text.Json.JsonSerializer.Deserialize <CadDocumentTree>(File.ReadAllText(_documentTree)); assertTable(doc.BlockRecords, tree.BlocksTable, doc.Header.Version >= ACadVersion.AC1021); }
public void CadDocumentDefaultTest() { CadDocument doc = new CadDocument(); DocumentIntegrity.AssertDocumentDefaults(doc); }
internal BlockRecordsTable(CadDocument document) : base(document) { }
public void CadDocumentTest() { CadDocument doc = new CadDocument(); DocumentIntegrity.AssertTableHirearchy(doc); }
internal UCSTable(CadDocument document) : base(document) { }
internal ViewsTable(CadDocument document) : base(document) { }
internal TextStylesTable(CadDocument document) : base(document) { }
public DwgDocumentBuilder(CadDocument document, DwgReaderFlags flags, NotificationEventHandler notification = null) : base(document, notification) { this.Flags = flags; }
public CadDocumentBuilder(CadDocument document, NotificationEventHandler notification = null) { this.DocumentToBuild = document; this.NotificationHandler = notification; }
private static void documentObjectNotNull <T>(CadDocument doc, T o) where T : CadObject { Assert.True(doc.GetCadObject(o.Handle) != null, $"Object of type {typeof(T)} | {o.Handle} not found in the doucment"); }