Skip to content

Commit

Permalink
Merge pull request #486 from DomCR/dynamic-blocks
Browse files Browse the repository at this point in the history
Dynamic blocks
  • Loading branch information
DomCR authored Jan 4, 2025
2 parents f0cbe70 + 3a2d0ab commit 0d0db03
Show file tree
Hide file tree
Showing 41 changed files with 18,535 additions and 458 deletions.
Binary file added samples/dynamic-blocks/dynamic-block-circle.dwg
Binary file not shown.
17,508 changes: 17,508 additions & 0 deletions samples/dynamic-blocks/dynamic-block-circle.dxf

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions src/ACadSharp.Tests/IO/DynamicBlockTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using ACadSharp.Entities;
using ACadSharp.IO;
using ACadSharp.Objects.Evaluations;
using ACadSharp.Tables;
using ACadSharp.Tests.TestModels;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests.IO
{
public class DynamicBlockTests : IOTestsBase
{
public static TheoryData<FileModel> DwgDynamicBlocksPaths { get; } = new();

static DynamicBlockTests()
{
loadSamples("dynamic-blocks", "*", DwgDynamicBlocksPaths);
}

public DynamicBlockTests(ITestOutputHelper output) : base(output)
{
}

[Theory]
[MemberData(nameof(DwgDynamicBlocksPaths))]
public void DynamicBlocksTest(FileModel test)
{
CadDocument doc;

if (test.Extension == ".dxf")
{
DxfReaderConfiguration configuration = new();
configuration.KeepUnknownEntities = true;
configuration.KeepUnknownNonGraphicalObjects = true;

doc = DxfReader.Read(test.Path, configuration, this.onNotification);
}
else
{
DwgReaderConfiguration configuration = new DwgReaderConfiguration();
configuration.KeepUnknownEntities = true;
configuration.KeepUnknownNonGraphicalObjects = true;

doc = DwgReader.Read(test.Path, configuration, this.onNotification);
}

//"my-dynamic-block" handle = 570

BlockRecord blk = doc.BlockRecords["my-dynamic-block"];

Assert.True(blk.IsDynamic);

//Dictionary entry
EvaluationGraph eval = blk.XDictionary.GetEntry<EvaluationGraph>("ACAD_ENHANCEDBLOCK");

//Extended data related to the dynamic block
var a = blk.ExtendedData.Get(doc.AppIds["AcDbBlockRepETag"]);
var b = blk.ExtendedData.Get(doc.AppIds["AcDbDynamicBlockTrueName"]);
var c = blk.ExtendedData.Get(doc.AppIds["AcDbDynamicBlockGUID"]);

Insert basic = doc.GetCadObject<Insert>(788);
Insert modified = doc.GetCadObject<Insert>(889);
}
}
}
10 changes: 7 additions & 3 deletions src/ACadSharp.Tests/TestModels/FileModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using Xunit.Abstractions;
using ACadSharp.IO;
using System.IO;
using Xunit.Abstractions;

namespace ACadSharp.Tests.TestModels
{
public class FileModel : IXunitSerializable
{
public string FileName { get; set; }
public string Extension { get { return System.IO.Path.GetExtension(Path); } }

public string Path { get; set; }
public string FileName { get; private set; }

public string Path { get; private set; }

public bool IsDxf { get { return System.IO.Path.GetExtension(this.Path) == ".dxf"; } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ACadSharp.Attributes
{
[System.AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
sealed class DxfCollectionCodeValueAttribute : Attribute, ICodeValueAttribute
public sealed class DxfCollectionCodeValueAttribute : Attribute, ICodeValueAttribute
{
/// <inheritdoc/>
public DxfCode[] ValueCodes { get; }
Expand Down
1 change: 1 addition & 0 deletions src/ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ACadSharp.Tables.Collections;
using ACadSharp.XData;
using System;
using ACadSharp.XData;
using System.Collections.Generic;

namespace ACadSharp
Expand Down
1 change: 1 addition & 0 deletions src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static class DxfFileToken
public const string ObjectXRecord = "XRECORD";
public const string ObjectMLeaderContextData = "CONTEXT_DATA";
public const string ObjectEvalGraph = "ACAD_EVALUATION_GRAPH";
public const string ObjectBlockLinearParameter = "BLOCKLINEARPARAMETER";
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";
public const string ObjectTableContent = "TABLECONTENT";

Expand Down
9 changes: 9 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ public static class DxfSubclassMarker
public const string PlotSettings = "AcDbPlotSettings";
public const string DictionaryVariables = "DictionaryVariables";
public const string Scale = "AcDbScale";

//Dynamic block constants
public const string EvalGraph = "AcDbEvalGraph";
public const string EvalGraphExpr = "AcDbEvalExpr";
public const string BlockElement = "AcDbBlockElement";
public const string BlockParameter = "AcDbBlockParameter";
public const string Block1PtParameter = "AcDbBlock1PtParameter";
public const string Block2PtParameter = "AcDbBlock2PtParameter";
public const string BlockLinearParameter = "AcDbBlockLinearParameter";

public const string BlockVisibilityParameter = "AcDbBlockVisibilityParameter";
public const string DbColor = "AcDbColor";
public const string TableContent = "AcDbTableContent";
Expand Down
Loading

0 comments on commit 0d0db03

Please sign in to comment.