DwgReader reads a color-book entity's Color as ByBlock instead of the book's color
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read DwgStreamReaderAC18.ReadEnColor and CadEntityTemplate.Build, which the issue identifies as the placeholder and BookColor resolution paths. Compare how the DWG reader assigns Entity.Color with the DXF result for the supplied sample files. Done means DwgReader reports the book color's RGB as Entity.Color across the listed DWG versions, while retaining the correct BookColor.
Written by the indexing model from the issue text.
Description
Describe the bug
For an entity with a color-book color, DwgReader sets Entity.Color to ByBlock. Entity.BookColor is
read correctly, and its Color holds the real RGB. AutoCAD shows the entity in that color, and DxfReader
returns it as Entity.Color for the same entity in the DXF version of the sample.
To Reproduce
using ACadSharp;
using ACadSharp.Entities;
using ACadSharp.IO;
string samples = args.Length > 0 ? args[0] : "samples";
var fromDxf = DxfReader.Read(Path.Combine(samples, "sample_AC1032_ascii.dxf"));
var c = fromDxf.GetCadObject<Circle>(0x99F);
Console.WriteLine($"DXF sample_AC1032_ascii.dxf: Color = {c.Color}, BookColor = {c.BookColor?.Name} ({c.BookColor?.Color})");
foreach (var file in new[] { "sample_AC1018.dwg", "sample_AC1032.dwg" })
{
var fromDwg = DwgReader.Read(Path.Combine(samples, file));
c = fromDwg.GetCadObject<Circle>(0x99F);
Console.WriteLine($"DWG {file}: Color = {c.Color}, BookColor = {c.BookColor?.Name} ({c.BookColor?.Color})");
}
Output:
DXF sample_AC1032_ascii.dxf: Color = True Color RGB:226,144,0, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)
DWG sample_AC1018.dwg: Color = ByBlock, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)
DWG sample_AC1032.dwg: Color = ByBlock, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)
sample_AC1021.dwg, sample_AC1024.dwg and sample_AC1027.dwg give the same result.
Expected behavior
Entity.Color is True Color RGB:226,144,0, which is the book color's color, as DxfReader returns.
Additional context
DwgStreamReaderAC18.ReadEnColor returns Color.ByBlock as a placeholder when flag 0x4000 is set
(L74-L79).
CadEntityTemplate.Build then resolves the BookColor from its handle
(L102-L106),
but never copies BookColor.Color into Entity.Color. Copying it there would probably fix this. I haven't tested that.
The same code is on master (edf487a). See also #1391 (DwgWriter writes an unreadable entity when it has both a true color and a BookColor).
Release needed
- Yes, using the Nuget package.
- No, using the github repo.
- Dominant language
- C#
- Stars
- 873
- Forks
- 223
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 28
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DomCR/ACadSharp
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
DWG writer: text styles get the text-style table as their xref block handlePossibly taken @menes97 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 81/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 3 days
-
DwgWriter writes a null shape-file handle for SHAPE entities (WriteShapes = true)Possibly taken @menes97 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
DomCR/ACadSharp#1334 · 1 comment ·
Maintainers usually reply within 3 days
Similar issues
-
hand-to-AI
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CactuseSecurity/firewall-orchestrator#5803 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug python
Difficulty 1/5 Under an hour Newbie friendliness 88/100
ilia-sokolov/OfficeAgent.NET#89 ·
Maintainers usually reply within 13 days