1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
.. _tut_hatch:
Tutorial for Hatch
==================
Create hatches with one boundary path
-------------------------------------
The simplest form of the :class:`~ezdxf.entities.Hatch` entity has one polyline
path with only straight lines as boundary path:
.. literalinclude:: src/hatch/solid_hatch_polyline_path.py
But like all polyline entities the polyline path can also have bulge values:
.. literalinclude:: src/hatch/solid_hatch_polyline_path_with_bulge.py
The most flexible way to define a boundary path is the edge path. An edge path
can have multiple edges and each edge can be one of the following elements:
- line :meth:`EdgePath.add_line`
- arc :meth:`EdgePath.add_arc`
- ellipse :meth:`EdgePath.add_ellipse`
- spline :meth:`EdgePath.add_spline`
Create a solid hatch with an edge path (ellipse) as boundary path:
.. literalinclude:: src/hatch/solid_hatch_ellipse.py
Create hatches with multiple boundary paths (islands)
-----------------------------------------------------
The DXF attribute :attr:`hatch_style` defines the island detection style:
=== ========================================================
0 nested - altering filled and unfilled areas
1 outer - area between `external` and `outermost` path is filled
2 ignore - `external` path is filled
=== ========================================================
.. literalinclude:: src/hatch/solid_hatch_islands.py
:lines: 11-27
This is also the result for all 4 paths and :attr:`hatch_style` set to ``2``
(ignore).
.. image:: gfx/hatch-island-01.png
:align: center
.. literalinclude:: src/hatch/solid_hatch_islands.py
:lines: 31-36
This is also the result for all 4 paths and :attr:`hatch_style` set to ``1``
(outer).
.. image:: gfx/hatch-island-02.png
:align: center
.. literalinclude:: src/hatch/solid_hatch_islands.py
:lines: 40-45
.. image:: gfx/hatch-island-03.png
:align: center
.. literalinclude:: src/hatch/solid_hatch_islands.py
:lines: 49-56
.. image:: gfx/hatch-island-04.png
:align: center
The expected result of combinations of various :attr:`hatch_style` values and
paths `flags`, or the handling of overlapping paths is not documented by the
DXF reference, so don't ask me, ask Autodesk or just try it by yourself
and post your experience in the forum.
Example for Edge Path Boundary
------------------------------
.. literalinclude:: src/hatch/edge_path.py
:lines: 8-56
.. image:: gfx/hatch-edge-path.png
:align: center
Associative Boundary Paths
--------------------------
A HATCH entity can be associative to a base geometry, which means if the base
geometry is edited in a CAD application the HATCH get the same modification.
Because `ezdxf` is **not** a CAD application, this association is **not**
maintained nor verified by `ezdxf`, so if you modify the base geometry
afterwards the geometry of the boundary path is not updated and no verification
is done to check if the associated geometry matches the boundary path, this
opens many possibilities to create invalid DXF files: USE WITH CARE.
This example associates a LWPOLYLINE entity to the hatch created from the
LWPOLYLINE vertices:
.. literalinclude:: src/hatch/assoc_hatch.py
:lines: 8-24
An :class:`EdgePath` needs associations to all geometry entities forming the
boundary path.
Predefined Hatch Pattern
------------------------
Use predefined hatch pattern by name:
.. code-block:: Python
hatch.set_pattern_fill("ANSI31", scale=0.5)
.. image:: gfx/hatch-predefined-pattern.png
:align: center
Create hatches with gradient fill
---------------------------------
TODO
|