I use QCAD C++ dxflib to create dxf files.
I can create shapes as circles, but I cannot fill them with a solid hatch. I cannot figure it out from the examples.
May you help me?
Hi,
Are you working in radians or are you using degrees … ![]()
Read: dxf->writeHatch, but how ? - dxflib 'How Do I' Questions - QCAD Forum
Or maybe the issue is based on how boundaries of a Hatch are defined.
If we create a circular hatched area with the QCAD GUI then it is initially stored as Circle for boundary until saved/reloaded.
After reloading they appear to be stored as a full 2PI Arc … Or the bulging factor = 1.66312e+16.
That itself is an error because the bulging factor of an Arc is equal to tan(Sweep/4) and for a full circular Arc the tangent of PI/2 does not exist.
The same is true for Polylines with bulging segments and in a way that was fixed.
Newer art is that a Circle explodes to a Polyline with 2 semi circular arcs … Or both the bulging factors are 1.00 and thus not an error.
I found ‘the examples’ via Stack Overflow linked to: ![]()
This shows how a 2PI Arc segment is added to a hatch with one single boundary loop.
All starts with configuring attributes in line 70 and ends in line 95.
For a solid hatch DL_HatchData data(1, true, 1.0, 0.0, pattern, 0.0, 0.0);
pattern should not matter I think, perhaps an empty string or ‘SOLID’.
For now I can not pinpoint what the values in red are for.
(only found dxflib/2.5/classref)
Regards,
CVH
Thanks,
I don’t know if I should call it a hatch, but my goal is to fill with solid white a circle I have inserted.
Looking at the dxf file (done with QCAD), if
this is the simple circle:
AcDbCircle
10
0.0
20
0.0
30
0.0
40
100.0
0
this is the dxf section added when I insert the solid hatch:
HATCH
5
109
330
127
100
AcDbEntity
8
0
440
33554687
100
AcDbHatch
10
0.0
20
0.0
30
0.0
210
0.0
220
0.0
230
1.0
2
SOLID
70
1
71
0
91
1
92
0
93
1
72
2
10
0.0
20
0.0
40
100.0
50
0.0
51
360.0
73
1
97
0
75
0
76
1
98
0
0
How this can be done programmatically with dxflib?
A solid fill of an arbitrary closed shape is by hatching it.
It is even possible to omit the boundary shape itself.
I think the linked examples speak for themselves.
Line 70 : set attributes
Line 73 : start hatch with one loop (A hatch can have multiple boundary loops)
Line 77 : start loop 1
Line 81 : write edge (In this case one single edge … a full arc See: dxflib: DL_HatchEdgeData Struct Reference)
Line 92 : end loop 1
Line 95 : end hatch
This one is very similar:
That is how far I can help you with this.
Regards,
CVH
Finally, I realized why pasting the example in my code was not working; I was using this version
DL_Codes::version exportVersion = DL_Codes::AC1009;
and the hatch seems not to be working in that version (the sample too). Setting the version to
DL_Codes::version exportVersion = DL_Codes::AC1015;
then it works.
Thanks for the help.
Both given examples included DL_Codes::AC1015. ![]()
Glad it worked out … ![]()
Could you provide the dxf with the full arc just as reference?
I suspect the bulge to be 1.66312e+16 what in fact is an error.
The arc is then 359.99999999999998622° what is about 1ULP less than a circular arc.
Please add [Solved] to the title of your initial posting.
Regards,
CVH
Here is a dxf
hatch.dxf (4.23 KB)
with a single circle.
For some reason even if I use the BYLAYER fill color, the fill is black
…
There is indeed a Black Hatch → handle 0x1000e
But also a mystery Black Hatch → handle 0x1000c
And a circle R=10 → handle 0x1000d
On AutoSave I get:
Exception occurred. Entity NOT saved: 1000c
This Hatch has zero vertices listed
… X,Y&Z are blank. ![]()
Regards,
CVH
Have a look here:
Color is the second attribute and it is of type ‘int’.
See also: dxflib: DL_Codes Class Reference
Regards,
CVH