diff --git a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs index 93d3cd12..33e6300f 100644 --- a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs +++ b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs @@ -501,6 +501,12 @@ public void XData() records.Add(new ExtendedDataInteger32(33)); records.Add(new ExtendedDataString("my extended data string")); records.Add(new ExtendedDataHandle(5)); + records.Add(new ExtendedDataReal(25.35)); + records.Add(new ExtendedDataScale(0.66)); + records.Add(new ExtendedDataDistance(481.48)); + records.Add(new ExtendedDataDirection(new XYZ(4, 3, 2))); + records.Add(new ExtendedDataCoordinate(new XYZ(8, 7, 4))); + records.Add(new ExtendedDataWorldCoordinate(new XYZ(85, 74, 47))); records.Add(new ExtendedDataLayer(layer.Handle)); records.Add(new ExtendedDataBinaryChunk(new byte[] { 1, 2, 3, 4 })); records.Add(new ExtendedDataControlString(true)); diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs index 1051ab21..0b9d83c3 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs @@ -331,10 +331,13 @@ private void writeEntityMode(Entity entity) private void writeExtendedData(ExtendedDataDictionary data) { - //EED size BS size of extended entity data, if any - foreach (var item in data.Entries) + if (this.WriteXData) { - writeExtendedDataEntry(item.Key, item.Value); + //EED size BS size of extended entity data, if any + foreach (var item in data.Entries) + { + writeExtendedDataEntry(item.Key, item.Value); + } } this._writer.WriteBitShort(0); @@ -364,6 +367,9 @@ private void writeExtendedDataEntry(AppId app, ExtendedData entry) case ExtendedDataInteger32 s32: mstream.Write(LittleEndianConverter.Instance.GetBytes(s32.Value), 0, 4); break; + case ExtendedDataReal real: + mstream.Write(LittleEndianConverter.Instance.GetBytes(real.Value), 0, 8); + break; case ExtendedDataScale scale: mstream.Write(LittleEndianConverter.Instance.GetBytes(scale.Value), 0, 8); break; diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs index 1270b39f..34ed5f94 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs @@ -24,6 +24,8 @@ internal partial class DwgObjectWriter : DwgSectionIO public bool WriteXRecords { get; } + public bool WriteXData { get; } + private Dictionary _dictionaries = new(); private Queue _objects = new(); @@ -40,7 +42,7 @@ internal partial class DwgObjectWriter : DwgSectionIO private Entity _next; - public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, bool writeXRecords = true) : base(document.Header.Version) + public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, bool writeXRecords = true, bool writeXData = true) : base(document.Header.Version) { this._stream = stream; this._document = document; @@ -48,6 +50,7 @@ public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, b this._msmain = new MemoryStream(); this._writer = DwgStreamWriterBase.GetMergedWriter(document.Header.Version, this._msmain, encoding); this.WriteXRecords = writeXRecords; + this.WriteXData = writeXData; } public void Write() diff --git a/src/ACadSharp/IO/DWG/DwgWriter.cs b/src/ACadSharp/IO/DWG/DwgWriter.cs index 3b25c7f3..f179ea1e 100644 --- a/src/ACadSharp/IO/DWG/DwgWriter.cs +++ b/src/ACadSharp/IO/DWG/DwgWriter.cs @@ -291,7 +291,12 @@ private void writeRevHistory() private void writeObjects() { MemoryStream stream = new MemoryStream(); - DwgObjectWriter writer = new DwgObjectWriter(stream, this._document, this._encoding, this.Configuration.WriteXRecords); + DwgObjectWriter writer = new DwgObjectWriter( + stream, + this._document, + this._encoding, + this.Configuration.WriteXRecords, + this.Configuration.WriteXData); writer.OnNotification += this.triggerNotification; writer.Write();