Closed AFriendlyGuy closed 2 years ago
Can you check something for me? It looks like the difference is that AutoCAD generated codes 2, 70, 71, but this library generated 2, 70, 63, 71. Can you manually swap the 63 and 71 codes and try to open that? You can use Notepad or any basic text editor to make the relevant portion of the file read:
...
2
SOLID
70
0
71
0
63
256
...
The swap changes the error message to "code 91 expected". Swapping this code also changes the error message. It looks like the order of the code should be exactly the same as in the case generated by AutoCAD. I adjusted the order until I got the error message "code 73 expected". According to the specs this is the code for the "Is closed"-flag for the polyline boundary data. It is missing in the output of the library.
Maybe the problem is
92
2
which indicates that the boundary is a polyline despite the fact that I used NonPolylineBoundaryPath
.
I changed the c# code to generate a polyline boundary path:
var boundaryPath = new DxfHatch.PolylineBoundaryPath { IsClosed = true };
for(var i=0; i < v.Length; ++i)
boundaryPath.Vertices.Add(new DxfVertex(v[i]));
var hatch = new DxfHatch {
FillMode = DxfHatchPatternFillMode.SolidFill,
FillColor = DxfColor.FromIndex(color),
PatternName = "SOLID",
};
hatch.BoundaryPaths.Add(boundaryPath);
Then I had to do the following adjustments (left side version accepted by AutoCAD, right side library output):
Thank you for figuring out the correct order of the codes, this is hugely valuable. Ultimately the fix is going to need to exist in EntitiesSpec.xml and I'd like it if the changes somewhat matched what the 2018 spec says about HATCH
.
63
that apparently needs to be removed, the spec says "For MPolygon, pattern fill color as the ACI". There are several properties with the predicate "For MPolygon", but I don't see what would classify a hatch as an MPolygon. Admittedly I'm not terribly familiar with the intricacies of AutoCAD, do you know what "MPolygon" could refer to? If we can figure out when this value should be written or suppressed, a WriteCondition=""
could be added here.78
is written here, I'm guessing a write condition should be added along the lines of PatternDefinitionLines.Count != 0
.47
for pixel size. The spec mentions "for associative hatches and hatches created with the Flood method of hatching" and code 71
specifies if the hatch is associative, so perhaps a write condition of IsAssociative
would suffice? I'm not sure what "Flood" means in this context, though.452
and 453
. It looks like these just need to be moved down a bit?463
. The spec says it's reserved, so perhaps writing this value should be disabled?What are your thoughts on the above? I can work on some changes to address items 2-5, but I don't know what to do about item 1, code 63
and "MPolygon".
I am not an expert on AutoCAD or DXF files. I am just trying to write an DXF-export for my tool. Having said this, here are my guesses: Concerning MPolygon the specs says in the very beginning:
The following group codes apply to hatch and MPolygon entities.
I would conclude that MPolygon is a different kind of entity which happens to be very similar to a hatch and shares most of the group codes. But I have no idea how to create a MPolygon in AutoCAD.
Concering 3.: Maybe it is better to related it to code 70 == 0
(pattern fill)? The specs says
... in hatch pattern computation for associative hatches ...
I agree with you on the other points.
I've added a branch write-hatch
with some changes, can you see if it helps your scenario?
It includes the following changes from above:
63
. I have no idea what "MPolygon" could mean; I'll have to revisit this.78
.FillMode == DxfHatchPatternFillMode.SolidFill || IsAssociative
. That way the "for associative hatches" condition is met as well as "hatches created with [] Flood" (I'm equating SolidFill
with Flood.)452
and 453
have been moved.463
has been removed.Everything is fine now except the condition FillMode == DxfHatchPatternFillMode.SolidFill || IsAssociative
did not work for me. One can have solid fill and still AutoCAD does not expect the group code 47
. After changing it to IsAssociative
as you proposed in the beginning it worked for me.
Can you clarify some points for me?
42
was unexpected. HATCH
doesn't use this code, presumably this was a typo for 47
?FillMode
is an enum with values of PatternFill
(0) and SolidFill
(1), while IsAssociative
is a bool
.Sorry for the confusion. It was already late yesterday when I wrote the comment and I got disturbed several times. I corrected it. What I meant was:
47
indeed.IsAssociative
instead of FillMode == DxfHatchPatternFillMode.SolidFill || IsAssociative
I played around with AutoCAD to generate a hatch containing group code 47
, but I was not successful. Instead AutoCAD just froze quite frequently.
I've force-pushed to the write-hatch
branch with your condition change. If you could give it a quick check to make sure I set the condition appropriately, I'll merge this back to main
.
The current version of write-hatch
works for me.
Thanks for checking, I've merged these changed back to main
via commit 38ecfd51d3222dab5dd5ef7198327823133ef997.
The creation of a hatch yielded an dxf file, which AutoCAD 2022 could not read.
The hatch was created like this (inspired by #136):
The error message in AutoCAD was the following (translated from German):
Here is the relevant part from the dxf file starting at line 1930, it contains the code 71:
A hatch generated from within AutoCAD looks slightly different: