DwgWriter writes a null shape-file handle for SHAPE entities (WriteShapes = true)
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start in DwgObjectWriter.writeShape at the SHAPEFILE handle serialization cited in the issue, then trace how DwgObjectReader.readShape restores ShapeFileHandle and how Shape.ShapeStyle supplies it. Use the reproduction to write and read the sample DWG with WriteShapes = true; done means ShapeStyle remains unnamed1 after the round trip.
Written by the indexing model from the issue text.
Description
Describe the bug
With WriteShapes = true, DwgWriter writes SHAPE entities but always writes a null SHAPEFILE handle. The shape
loses its shape file, and Shape.ShapeStyle is null after the file is read back. DxfWriter keeps it.
To Reproduce
using ACadSharp;
using ACadSharp.Entities;
using ACadSharp.IO;
string samples = args.Length > 0 ? args[0] : "samples";
var doc = DwgReader.Read(Path.Combine(samples, "sample_AC1032.dwg"));
var shape = doc.GetCadObject<Shape>(0x889);
Console.WriteLine($"Read: ShapeStyle = {shape.ShapeStyle?.Name ?? "null"} (shape file: {shape.ShapeStyle?.IsShapeFile})");
DwgWriter.Write("shape.dwg", doc, new DwgWriterConfiguration { WriteShapes = true });
var back = DwgReader.Read("shape.dwg");
shape = back.GetCadObject<Shape>(0x889);
Console.WriteLine($"After DWG round trip: ShapeStyle = {shape.ShapeStyle?.Name ?? "null"}");
Output:
Read: ShapeStyle = unnamed1 (shape file: True)
After DWG round trip: ShapeStyle = null
Expected behavior
ShapeStyle is still unnamed1 after the round trip.
Additional context
DwgObjectWriter.writeShape writes HandleReference(DwgReferenceType.HardPointer, null) for the SHAPEFILE handle
(L2390-L2391).
DwgObjectReader.readShape reads that handle back into ShapeFileHandle. Writing shape.ShapeStyle there would
probably fix this. I haven't tested that.
A suggestion: when WriteShapes is false (the default), both writers skip shapes without a notification.
A NotImplemented notification, like the one DxfWriter raises for TableEntity, would let callers see that
something was left out.
The same code is on master (edf487a).
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
-
DwgReader reads a color-book entity's Color as ByBlock instead of the book's colorPossibly 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