From 83da807200f0e84bfb8e2bd58ca8dad6658dd313 Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 11:53:27 +0100 Subject: [PATCH] fix --- .../DWG/DwgStreamReaders/DwgObjectReader.cs | 2 +- .../DwgObjectWriter.Objects.cs | 30 +++++++++++++++---- .../DWG/DwgStreamWriters/DwgObjectWriter.cs | 11 +++++-- .../Objects/CadDictionaryWithDefault.cs | 5 +++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index a78448ab..08d1aa42 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -3654,7 +3654,7 @@ private CadTemplate readBlockHeader() //Common: //Entry name TV 2 - //Warning: names ended with a number are not readed in this method + //Warning: anonymous blocks do not write the full name, only *{type character} string name = this._textReader.ReadVariableText(); if (name.Equals(BlockRecord.ModelSpaceName, System.StringComparison.CurrentCultureIgnoreCase) || name.Equals(BlockRecord.PaperSpaceName, System.StringComparison.CurrentCultureIgnoreCase)) diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs index 8a1e27fa..7448349a 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs @@ -3,6 +3,7 @@ using CSUtilities.Converters; using CSUtilities.IO; using System; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -152,8 +153,25 @@ private void writeCadDictionaryWithDefault(CadDictionaryWithDefault dictionary) private void writeDictionary(CadDictionary dictionary) { //Common: - //Numitems L number of dictonary items - this._writer.WriteBitLong(dictionary.Count()); + //Numitems L number of dictionary items + List entries = new List(); + foreach (var item in dictionary) + { + if (item is XRecord && !this.WriteXRecords) + { + continue; + } + + if (item is UnknownNonGraphicalObject) + { + continue; + } + + entries.Add(item); + } + + //16 + this._writer.WriteBitLong(entries.Count); //R14 Only: if (this._version == ACadVersion.AC1014) @@ -171,16 +189,16 @@ private void writeDictionary(CadDictionary dictionary) } //Common: - foreach (var item in dictionary) + foreach (var item in entries) { if (item is XRecord && !this.WriteXRecords) { - return; + continue; } if (item is UnknownNonGraphicalObject) { - return; + continue; } this._writer.WriteVariableText(item.Name); @@ -730,4 +748,4 @@ private void writeXRecord(XRecord xrecord) } } -} +} \ No newline at end of file diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs index f7590efe..1270b39f 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs @@ -257,8 +257,15 @@ private void writeBlockHeader(BlockRecord record) //Common: //Entry name TV 2 - //Warning: names ended with a number are not readed in this method - this._writer.WriteVariableText(record.Name); + if (record.Flags.HasFlag(BlockTypeFlags.Anonymous)) + { + //Warning: anonymous blocks do not write the full name, only *{type character} + this._writer.WriteVariableText(record.Name.Substring(0, 2)); + } + else + { + this._writer.WriteVariableText(record.Name); + } this.writeXrefDependantBit(record); diff --git a/src/ACadSharp/Objects/CadDictionaryWithDefault.cs b/src/ACadSharp/Objects/CadDictionaryWithDefault.cs index 75d95f28..3fb35be3 100644 --- a/src/ACadSharp/Objects/CadDictionaryWithDefault.cs +++ b/src/ACadSharp/Objects/CadDictionaryWithDefault.cs @@ -13,10 +13,13 @@ namespace ACadSharp.Objects [DxfSubClass(DxfSubclassMarker.DictionaryWithDefault)] public class CadDictionaryWithDefault : CadDictionary { + /// public override ObjectType ObjectType { get { return ObjectType.UNLISTED; } } - public override string ObjectName => DxfFileToken.ObjectDictionary; + /// + public override string ObjectName => DxfFileToken.ObjectDictionaryWithDefault; + /// public override string SubclassMarker => DxfSubclassMarker.DictionaryWithDefault; ///