File: query.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 (134 lines) | stat: -rw-r--r-- 3,271 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
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
.. reference - usage is documented in tasks - "Query data"

.. module:: ezdxf.query

Query Module
============

.. seealso::

    - :ref:`tut_getting_data`
    - Usage of extended query features: :ref:`query entities`

The new() Function
++++++++++++++++++

.. autofunction:: ezdxf.query.new

.. _entity query string:

Entity Query String
-------------------

.. code-block::

    QueryString := EntityQuery ("[" AttribQuery "]" "i"?)*

The query string is the combination of two queries, first the required entity query and 
second the optional attribute query, enclosed in square brackets, append ``'i'`` after 
the closing square bracket to ignore case for strings.

Entity Query
++++++++++++

The entity query is a whitespace separated list of DXF entity names or the special name 
``'*'``. Where ``'*'`` means all DXF entities, exclude some entity types by appending 
their names with a preceding ``!`` (e.g. all entities except LINE = ``'* !LINE'``). 
All DXF names have to be uppercase.

Attribute Query
+++++++++++++++

The *optional* attribute query is a boolean expression, supported operators are:

  - not (!): !term is true, if term is false
  - and (&): term & term is true, if both terms are true
  - or (|): term | term is true, if one term is true
  - and arbitrary nested round brackets
  - append (i) after the closing square bracket to ignore case for strings

Attribute selection is a term: "name comparator value", where name is a DXF
entity attribute in lowercase, value is a integer, float or double quoted string,
valid comparators are:

  - ``==`` equal "value"
  - ``!=`` not equal "value"
  - ``<`` lower than "value"
  - ``<=`` lower or equal than "value"
  - ``>`` greater than "value"
  - ``>=`` greater or equal than "value"
  - ``?`` match regular expression "value"
  - ``!?`` does not match regular expression "value"


EntityQuery Class
-----------------

.. class:: EntityQuery

    The :class:`EntityQuery` class is a result container, which is filled with DXF 
    entities matching the query string. It is possible to add entities to the container 
    (extend), remove entities from the container and to filter the container. 
    Supports the standard Python Sequence methods and protocols.  
    Does not remove automatically destroyed entities (entities deleted by calling method 
    :meth:`destroy`), the method :meth:`purge` has to be called explicitly to remove the 
    destroyed entities.

    .. autoattribute:: first

    .. autoattribute:: last

    .. automethod:: __len__

    .. automethod:: __getitem__

    .. automethod:: __setitem__

    .. automethod:: __delitem__

    .. automethod:: __eq__

    .. automethod:: __ne__

    .. automethod:: __lt__

    .. automethod:: __le__

    .. automethod:: __gt__

    .. automethod:: __ge__

    .. automethod:: match

    .. automethod:: __or__

    .. automethod:: __and__

    .. automethod:: __sub__

    .. automethod:: __xor__

    .. automethod:: __iter__

    .. automethod:: purge

    .. automethod:: extend

    .. automethod:: remove

    .. automethod:: query

    .. automethod:: groupby

    .. automethod:: filter

    .. automethod:: union

    .. automethod:: intersection

    .. automethod:: difference

    .. automethod:: symmetric_difference