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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
|
Hatch
=====
.. module:: ezdxf.entities
:noindex:
The HATCH entity (`DXF Reference`_) fills a closed area defined by one or
more boundary paths by a hatch pattern, a solid fill, or a gradient fill.
All points in :ref:`OCS` as (x, y) tuples (:attr:`Hatch.dxf.elevation` is the
z-axis value).
There are two different hatch pattern default scaling, depending on the HEADER
variable $MEASUREMENT, one for ISO measurement (m, cm, mm, ...) and one for
imperial measurement (in, ft, yd, ...).
The default scaling for predefined hatch pattern will be chosen according this
measurement setting in the HEADER section, this replicates the behavior of
BricsCAD and other CAD applications. `Ezdxf` uses the ISO pattern definitions as
a base line and scales this pattern down by factor 1/25.6 for imperial
measurement usage.
The pattern scaling is independent from the drawing units of the document
defined by the HEADER variable $INSUNITS.
.. seealso::
:ref:`tut_hatch` and :ref:`DXF Units`
======================== ==========================================
Subclass of :class:`ezdxf.entities.DXFGraphic`
DXF type ``'HATCH'``
Factory function :meth:`ezdxf.layouts.BaseLayout.add_hatch`
Inherited DXF attributes :ref:`Common graphical DXF attributes`
Required DXF version DXF R2000 (``'AC1015'``)
======================== ==========================================
.. _DXF Reference: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-C6C71CED-CE0F-4184-82A5-07AD6241F15B
.. rubric:: Boundary paths classes
Path manager: :class:`BoundaryPaths`
- :class:`PolylinePath`
- :class:`EdgePath`
- :class:`LineEdge`
- :class:`ArcEdge`
- :class:`EllipseEdge`
- :class:`SplineEdge`
.. rubric:: Pattern and gradient classes
- :class:`Pattern`
- :class:`PatternLine`
- :class:`Gradient`
.. class:: Hatch
.. attribute:: dxf.pattern_name
Pattern name as string
.. attribute:: dxf.solid_fill
=== ==========================================================
1 solid fill, use method :meth:`Hatch.set_solid_fill`
0 pattern fill, use method :meth:`Hatch.set_pattern_fill`
=== ==========================================================
.. attribute:: dxf.associative
=== =========================
1 associative hatch
0 not associative hatch
=== =========================
Associations are not managed by `ezdxf`.
.. attribute:: dxf.hatch_style
=== ========
0 normal
1 outer
2 ignore
=== ========
(search AutoCAD help for more information)
.. attribute:: dxf.pattern_type
=== ===================
0 user
1 predefined
2 custom
=== ===================
.. attribute:: dxf.pattern_angle
The actual pattern rotation angle in degrees (float). Changing this value does not
rotate the pattern, use :meth:`~Hatch.set_pattern_angle` for this task.
.. attribute:: dxf.pattern_scale
The actual pattern scale factor (float). Changing this value does not
scale the pattern use :meth:`~Hatch.set_pattern_scale` for this task.
.. attribute:: dxf.pattern_double
1 = double pattern size else 0. (int)
.. attribute:: dxf.n_seed_points
Count of seed points (use :meth:`get_seed_points`)
.. attribute:: dxf.elevation
Z value represents the elevation height of the :ref:`OCS`. (float)
.. attribute:: paths
:class:`BoundaryPaths` object.
.. attribute:: pattern
:class:`Pattern` object.
.. attribute:: gradient
:class:`Gradient` object.
.. attribute:: seeds
A list of seed points as (x, y) tuples.
.. autoproperty:: has_solid_fill
.. autoproperty:: has_pattern_fill
.. autoproperty:: has_gradient_data
.. autoproperty:: bgcolor
.. automethod:: set_pattern_definition
.. automethod:: set_pattern_scale
.. automethod:: set_pattern_angle
.. automethod:: set_solid_fill
.. automethod:: set_pattern_fill
.. automethod:: set_gradient
.. automethod:: set_seed_points
.. automethod:: transform(m: Matrix44) -> Hatch
.. automethod:: associate
.. automethod:: remove_association
Boundary Paths
--------------
The hatch entity is build by different path types, these are the
filter flags for the :attr:`Hatch.dxf.hatch_style`:
- EXTERNAL: defines the outer boundary of the hatch
- OUTERMOST: defines the first tier of inner hatch boundaries
- DEFAULT: default boundary path
As you will learn in the next sections, these are more the recommended
usage type for the flags, but the fill algorithm doesn't care much about that,
for instance an OUTERMOST path doesn't have to be inside the EXTERNAL path.
Island Detection
----------------
In general the island detection algorithm works always from outside to inside
and alternates filled and unfilled areas. The area between then 1st and the 2nd
boundary is filled, the area between the 2nd and the 3rd boundary is unfilled
and so on. The different hatch styles defined by the :attr:`Hatch.dxf.hatch_style`
attribute are created by filtering some boundary path types.
Hatch Style
-----------
- HATCH_STYLE_IGNORE: Ignores all paths except the paths marked as EXTERNAL, if
there are more than one path marked as EXTERNAL, they are filled in NESTED
style. Creates no hatch if no path is marked as EXTERNAL.
- HATCH_STYLE_OUTERMOST: Ignores all paths marked as DEFAULT, remaining EXTERNAL
and OUTERMOST paths are filled in NESTED style. Creates no hatch if no path is
marked as EXTERNAL or OUTERMOST.
- HATCH_STYLE_NESTED: Use all existing paths.
Hatch Boundary Classes
----------------------
.. class:: BoundaryPaths
Defines the borders of the hatch, a hatch can consist of more than one path.
.. attribute:: paths
List of all boundary paths. Contains :class:`PolylinePath` and
:class:`EdgePath` objects. (read/write)
.. automethod:: external_paths
.. automethod:: outermost_paths
.. automethod:: default_paths
.. automethod:: rendering_paths
.. automethod:: append
.. automethod:: add_polyline_path
.. automethod:: add_edge_path
.. automethod:: polyline_to_edge_paths
.. automethod:: edge_to_polyline_paths
.. automethod:: arc_edges_to_ellipse_edges
.. automethod:: ellipse_edges_to_spline_edges
.. automethod:: spline_edges_to_line_edges
.. automethod:: all_to_spline_edges
.. automethod:: all_to_line_edges
.. automethod:: clear
.. class:: BoundaryPathType
.. attribute:: POLYLINE
polyline path type
.. attribute:: EDGE
edge path type
.. class:: PolylinePath
A polyline as hatch boundary path.
.. attribute:: type
Path type as :attr:`BoundaryPathType.POLYLINE` enum
.. attribute:: path_type_flags
(bit coded flags)
=== ====================================
0 default
1 external
2 polyline, will be set by `ezdxf`
4 derived (?)
8 textbox
16 outermost
=== ====================================
My interpretation of the :attr:`path_type_flags`, see also :ref:`tut_hatch`:
- external: path is part of the hatch outer border
- outermost: path is completely inside of one or more external paths
- default: path is completely inside of one or more outermost paths
If there are troubles with AutoCAD, maybe the hatch entity has the
:attr:`Hatch.dxf.pixel_size` attribute set - delete it
:code:`del hatch.dxf.pixel_size` and maybe the problem is solved.
`Ezdxf` does not use the :attr:`Hatch.dxf.pixel_size` attribute, but it
can occur in DXF files created by other applications.
.. attribute:: PolylinePath.is_closed
``True`` if polyline path is closed.
.. attribute:: vertices
List of path vertices as (x, y, bulge)-tuples. (read/write)
.. attribute:: source_boundary_objects
List of handles of the associated DXF entities for associative hatches.
There is no support for associative hatches by `ezdxf`, you have to do
it all by yourself. (read/write)
.. automethod:: set_vertices
.. automethod:: clear
.. class:: EdgePath
Boundary path build by edges. There are four different edge types:
:class:`LineEdge`, :class:`ArcEdge`, :class:`EllipseEdge` of :class:`SplineEdge`.
Make sure there are no gaps between edges and the edge path must be closed
to be recognized as path. AutoCAD is very picky in this regard.
`Ezdxf` performs no checks on gaps between the edges and does not prevent
creating open loops.
.. note::
:class:`ArcEdge` and :class:`EllipseEdge` are ALWAYS represented in
counter-clockwise orientation, even if an clockwise oriented edge is
required to build a closed loop. To add a clockwise oriented curve swap
start- and end angles and set the `ccw` flag to `False` and `ezdxf`
will export a correct clockwise orientated curve.
.. attribute:: type
Path type as :attr:`BoundaryPathType.EDGE` enum
.. attribute:: path_type_flags
(bit coded flags)
=== ==============
0 default
1 external
16 outermost
=== ==============
see :attr:`PolylinePath.path_type_flags`
.. attribute:: edges
List of boundary edges of type :class:`LineEdge`, :class:`ArcEdge`,
:class:`EllipseEdge` of :class:`SplineEdge`
.. attribute:: source_boundary_objects
Required for associative hatches, list of handles to the associated DXF
entities.
.. automethod:: clear
.. automethod:: add_line
.. automethod:: add_arc
.. automethod:: add_ellipse
.. automethod:: add_spline
.. automethod:: close_gaps
.. class:: EdgeType
.. attribute:: LINE
.. attribute:: ARC
.. attribute:: ELLIPSE
.. attribute:: SPLINE
.. class:: LineEdge
Straight boundary edge.
.. attribute:: type
Edge type as :attr:`EdgeType.LINE` enum
.. attribute:: start
Start point as (x, y)-tuple. (read/write)
.. attribute:: end
End point as (x, y)-tuple. (read/write)
.. class:: ArcEdge
Arc as boundary edge in counter-clockwise orientation,
see :meth:`EdgePath.add_arc`.
.. attribute:: type
Edge type as :attr:`EdgeType.ARC` enum
.. attribute:: center
Center point of arc as (x, y)-tuple. (read/write)
.. attribute:: radius
Arc radius as float. (read/write)
.. attribute:: start_angle
Arc start angle in counter-clockwise orientation in degrees. (read/write)
.. attribute:: end_angle
Arc end angle in counter-clockwise orientation in degrees. (read/write)
.. attribute:: ccw
``True`` for counter clockwise arc else ``False``. (read/write)
.. class:: EllipseEdge
Elliptic arc as boundary edge in counter-clockwise orientation,
see :meth:`EdgePath.add_ellipse`.
.. attribute:: type
Edge type as :attr:`EdgeType.ELLIPSE` enum
.. attribute:: major_axis_vector
Ellipse major axis vector as (x, y)-tuple. (read/write)
.. attribute:: minor_axis_length
Ellipse minor axis length as float. (read/write)
.. attribute:: radius
Ellipse radius as float. (read/write)
.. attribute:: start_angle
Ellipse start angle in counter-clockwise orientation in degrees. (read/write)
.. attribute:: end_angle
Ellipse end angle in counter-clockwise orientation in degrees. (read/write)
.. attribute:: ccw
``True`` for counter clockwise ellipse else ``False``. (read/write)
.. class:: SplineEdge
Spline as boundary edge.
.. attribute:: type
Edge type as :attr:`EdgeType.SPLINE` enum
.. attribute:: degree
Spline degree as int. (read/write)
.. attribute:: rational
1 for rational spline else 0. (read/write)
.. attribute:: periodic
1 for periodic spline else 0. (read/write)
.. attribute:: knot_values
List of knot values as floats. (read/write)
.. attribute:: control_points
List of control points as (x, y)-tuples. (read/write)
.. attribute:: fit_points
List of fit points as (x, y)-tuples. (read/write)
.. attribute:: weights
List of weights (of control points) as floats. (read/write)
.. attribute:: start_tangent
Spline start tangent (vector) as (x, y)-tuple. (read/write)
.. attribute:: end_tangent
Spline end tangent (vector) as (x, y)-tuple. (read/write)
Hatch Pattern Definition Classes
--------------------------------
.. class:: Pattern
.. attribute:: lines
List of pattern definition lines (read/write). see :class:`PatternLine`
.. automethod:: add_line
.. automethod:: clear
.. automethod:: scale
.. class:: PatternLine
Represents a pattern definition line, use factory function :meth:`Pattern.add_line`
to create new pattern definition lines.
.. attribute:: angle
Line angle in degrees. (read/write)
.. attribute:: base_point
Base point as (x, y)-tuple. (read/write)
.. attribute:: offset
Offset as (x, y)-tuple. (read/write)
.. attribute:: dash_length_items
List of dash length items (item > 0 is line, < 0 is gap, 0.0 = dot). (read/write)
Hatch Gradient Fill Class
-------------------------
.. class:: Gradient
.. attribute:: color1
First rgb color as (r, g, b)-tuple, rgb values in range 0 to 255. (read/write)
.. attribute:: color2
Second rgb color as (r, g, b)-tuple, rgb values in range 0 to 255. (read/write)
.. attribute:: one_color
If :attr:`one_color` is 1 - the hatch is filled with a smooth transition between
:attr:`color1` and a specified :attr:`tint` of :attr:`color1`. (read/write)
.. attribute:: rotation
Gradient rotation in degrees. (read/write)
.. attribute:: centered
Specifies a symmetrical gradient configuration. If this option is not
selected, the gradient fill is shifted up and to the left, creating the
illusion of a light source to the left of the object. (read/write)
.. attribute:: tint
Specifies the tint (:attr:`color1` mixed with white) of a color to be
used for a gradient fill of one color. (read/write)
.. seealso::
:ref:`tut_hatch_pattern`
|