# Fill a solid circle with QCAD dxflib \[Solved\]

**URL:** <http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785>\
**Category:** dxflib Suggestions and Feedback\
**Created:** [January 9, 2023, 9:55am UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785 "2023-01-09T09:55:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![spiovesan](http://forum.qcad.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](http://forum.qcad.org/u/spiovesan)\
**Post date:** [January 9, 2023, 9:55am UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/1 "2023-01-09T09:55:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CVH](http://forum.qcad.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@CVH](http://forum.qcad.org/u/CVH)\
**Post date:** [January 9, 2023, 9:17pm UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/2 "2023-01-09T21:17:37Z")

</div>

Hi,  
Are you working in radians or are you using degrees … 😒  
Read: [dxf-\>writeHatch, but how ? - dxflib 'How Do I' Questions - QCAD Forum](https://forum.qcad.org/viewtopic.php?f=21&t=823&p=8941&#p8942)  
  
  
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: 😉

> <https://github.com/qcad/qcad/blob/master/support/examples/dxflib/main.cpp>

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

---

<div class="post-metadata">

**Author:** ![spiovesan](http://forum.qcad.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](http://forum.qcad.org/u/spiovesan)\
**Post date:** [January 10, 2023, 11:41am UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/3 "2023-01-10T11:41:36Z")

</div>

Thanks,  
I don’t know if I should call it a hatch, but my goal is to [fill with solid white a circle](https://visionlinksrl-my.sharepoint.com/:i:/g/personal/stefano_piovesan_univision_it/ETr03ecpgyhEnVK7xW4Y5bUBtL-NhP0u2B45KIueqHxxfw?e=mkPqnc) I have inserted.  
Looking at the dxf file (done with QCAD), if  
this is the simple circle:

```plaintext
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:

```plaintext
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?

---

<div class="post-metadata">

**Author:** ![CVH](http://forum.qcad.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@CVH](http://forum.qcad.org/u/CVH)\
**Post date:** [January 10, 2023, 7:56pm UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/4 "2023-01-10T19:56:13Z")

</div>

> [@](#):
>
> I don’t know if I should call it a hatch.

A solid fill of an arbitrary closed shape is by hatching it.  
It is even possible to omit the boundary shape itself.

> [@](#):
>
> How this can be done programmatically with dxflib?

I think the linked examples speak for themselves.

> <https://github.com/qcad/qcad/blob/master/support/examples/dxflib/main.cpp>

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](https://qcad.org/doc/dxflib/2.5/classref/struct_d_l___hatch_edge_data.html))  
Line 92 : end loop 1  
Line 95 : end hatch

This one is very similar:

> **[dxf-\>writeHatch, but how ?](https://forum.qcad.org/viewtopic.php?f=21&t=823&p=8941&#p8942)**
>
> I havent found how to write a hatch into dxf We have: void DL\_Dxf::writeHatch1 ( DL\_WriterA & dw, const DL\_HatchData & data, const DL\_Attributes & attrib ) where DL\_HatchData (int hNumLoops, bool hSolid, double hScale, double...

That is how far I can help you with this.

Regards,  
CVH

---

<div class="post-metadata">

**Author:** ![spiovesan](http://forum.qcad.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](http://forum.qcad.org/u/spiovesan)\
**Post date:** [January 16, 2023, 6:53am UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/5 "2023-01-16T06:53:23Z")

</div>

Finally, I realized why pasting the example in my code was not working; I was using this version

```plaintext
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

```plaintext
DL_Codes::version exportVersion = DL_Codes::AC1015;

```

then it works.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![CVH](http://forum.qcad.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@CVH](http://forum.qcad.org/u/CVH)\
**Post date:** [January 16, 2023, 7:25am UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/6 "2023-01-16T07:25:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spiovesan](http://forum.qcad.org/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@spiovesan](http://forum.qcad.org/u/spiovesan)\
**Post date:** [January 16, 2023, 1:50pm UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/7 "2023-01-16T13:50:32Z")

</div>

Here is a dxf  
[hatch.dxf](http://forum.qcad.org/uploads/short-url/q5NJm76Doxcu6A0FabuNXElnHLh.dxf) (4.23 KB)  
with a single circle.  
For some reason even if I use the BYLAYER fill color, the fill is black 😕 …

---

<div class="post-metadata">

**Author:** ![CVH](http://forum.qcad.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@CVH](http://forum.qcad.org/u/CVH)\
**Post date:** [January 16, 2023, 6:45pm UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/8 "2023-01-16T18:45:13Z")

</div>

> [@](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![CVH](http://forum.qcad.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@CVH](http://forum.qcad.org/u/CVH)\
**Post date:** [January 16, 2023, 6:59pm UTC](http://forum.qcad.org/t/fill-a-solid-circle-with-qcad-dxflib-solved/7785/9 "2023-01-16T18:59:56Z")

</div>

Have a look here:

> **[dxflib: DL\_Attributes Class Reference](https://qcad.org/doc/dxflib/2.5/classref/class_d_l___attributes.html)**

Color is the second attribute and it is of type ‘int’.  
See also: [dxflib: DL\_Codes Class Reference](https://qcad.org/doc/dxflib/2.5/classref/class_d_l___codes.html)

Regards,  
CVH
