File: gfxattribs.rst

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (89 lines) | stat: -rw-r--r-- 2,644 bytes parent folder | download
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
GfxAttribs
==========

.. module:: ezdxf.gfxattribs

The :mod:`ezdxf.gfxattribs` module provides the :class:`GfxAttribs` class to
create valid attribute dictionaries for the most often used DXF attributes
supported by all graphical DXF entities. The advantage of using this class
is auto-completion support by IDEs and an instant validation of the attribute
values.

.. code-block:: Python

    import ezdxf
    from ezdxf.gfxattribs import GfxAttribs

    doc = ezdxf.new()
    msp = doc.modelspace()

    attribs = GfxAttribs(layer="MyLayer", color=ezdxf.colors.RED)
    line = msp.add_line((0, 0), (1, 0), dxfattribs=attribs)
    circle = msp.add_circle((0, 0), radius=1.0, dxfattribs=attribs)

    # Update DXF attributes of existing entities:
    attribs = GfxAttribs(layer="MyLayer2", color=ezdxf.colors.BLUE)

    # Convert GfxAttribs() to dict(), but this method cannot reset
    # attributes to the default values like setting layer to "0".
    line.update_dxf_attribs(dict(attribs))

    # Using GfxAttribs.asdict(default_values=True), can reset attributes to the
    # default values like setting layer to "0", except for true_color and
    # transparency, which do not have default values, their absence is the
    # default value.
    circle.update_dxf_attribs(attribs.asdict(default_values=True))

    # Remove true_color and transparency by assigning None
    attribs.transparency = None  # reset to transparency by layer!
    attribs.rgb = None


Validation features:

- **layer** - string which can not contain certain characters: ``<>/\":;?*=```
- **color** - :ref:`ACI` value as integer in the range from 0 to 257
- **rgb** - true color value as (red, green, blue) tuple, all channel values as
  integer values in the range from 0 to 255
- **linetype** - string which can not contain certain characters: ``<>/\":;?*=```,
  does not check if the linetype exists
- **lineweight** - integer value in the range from 0 to 211, see :ref:`lineweights`
  for valid values
- **transparency** - float value in the range from 0.0 to 1.0 and -1.0 for transparency by block
- **ltscale** - float value > 0.0


.. autoclass:: GfxAttribs

    .. autoproperty:: layer

    .. autoproperty:: color

    .. autoproperty:: rgb

    .. autoproperty:: linetype

    .. autoproperty:: lineweight

    .. autoproperty:: transparency

    .. autoproperty:: ltscale

    .. automethod:: __str__

    .. automethod:: __repr__

    .. automethod:: __iter__

    .. automethod:: asdict

    .. automethod:: items

    .. automethod:: load_from_header

    .. automethod:: write_to_header

    .. automethod:: from_entity

    .. automethod:: from_dict