File: block_management.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 (328 lines) | stat: -rw-r--r-- 10,066 bytes parent folder | download | duplicates (3)
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
.. _Block Management Structures:

Block Management Structures
===========================

A BLOCK is a layout like the modelspace or a paperspace layout, with the
similarity that all these layouts are containers for graphical DXF entities.
This block definition can be referenced in other layouts by the INSERT entity.
By using block references, the same set of graphical entities can be located
multiple times at different layouts, this block references can be stretched and
rotated without modifying the original entities. A block is referenced only by
its name defined by the DXF tag :code:`(2, name)`, there is a second DXF tag
:code:`(3, name2)` for the block name, which is not further documented by
Autodesk, just ignore it.

The :code:`(10, base_point)` tag (in BLOCK defines a insertion point of the
block, by 'inserting' a block by the INSERT entity, this point of the block is
placed at the location defined by the :code:`(10, insert)` tag in
the INSERT entity, and it is also the base point for stretching and rotation.

A block definition can contain INSERT entities, and it is possible to create
cyclic block definitions (a BLOCK contains a INSERT of itself), but this should
be avoided, CAD applications will not load the DXF file at all or maybe just
crash. This is also the case for all other kinds of cyclic definitions like:
BLOCK "A" -> INSERT BLOCK "B" and BLOCK "B" -> INSERT BLOCK "A".


.. seealso::

    - ezdxf DXF Internals: :ref:`blocks_section_internals`
    - DXF Reference: `BLOCKS Section`_
    - DXF Reference: `BLOCK Entity`_
    - DXF Reference: `ENDBLK Entity`_
    - DXF Reference: `INSERT Entity`_

Block Names
-----------

Block names has to be unique and they are case insensitive ("Test" == "TEST").
If there are two or more block definitions with the same name, AutoCAD
merges these blocks into a single block with unpredictable properties
of all these blocks. In my test with two blocks, the final block has the name
of the first block and the base-point of the second block, and contains all
entities of both blocks.

Block Definitions in DXF R12
----------------------------

In DXF R12 the definition of a block is located in the BLOCKS section, no
additional structures are needed.
The definition starts with a BLOCK entity and ends with a ENDBLK entity.
All entities between this two entities are the content of the block, the block
is the owner of this entities like any layout.

As shown in the DXF file below (created by AutoCAD LT 2018), the BLOCK entity
has no handle, but ezdxf writes also handles for the BLOCK entity and AutoCAD
doesn't complain.

DXF R12 BLOCKS structure:

.. code-block:: none

    0           <<< start of a SECTION
    SECTION
    2           <<< start of BLOCKS section
    BLOCKS
    ...         <<< modelspace and paperspace block definitions not shown,
    ...         <<< see layout management
    ...
    0           <<< start of a BLOCK definition
    BLOCK
    8           <<< layer
    0
    2           <<< block name
    ArchTick
    70          <<< flags
    1
    10          <<< base point, x
    0.0
    20          <<< base point, y
    0.0
    30          <<< base point, z
    0.0
    3           <<< second BLOCK name, same as (2, name)
    ArchTick
    1           <<< xref name, if block is an external reference
                <<< empty string!
    0           <<< start of the first entity of the BLOCK
    LINE
    5
    28E
    8
    0
    62
    0
    10
    500.0
    20
    500.0
    30
    0.0
    11
    500.0
    21
    511.0
    31
    0.0
    0           <<< start of the second entity of the BLOCK
    LINE
    ...
    0.0
    0           <<< ENDBLK entity, marks the end of the BLOCK definition
    ENDBLK
    5           <<< ENDBLK gets a handle by AutoCAD, but BLOCK didn't
    2F2
    8           <<< as every entity, also ENDBLK requires a layer (same as BLOCK entity!)
    0
    0           <<< start of next BLOCK entity
    BLOCK
    ...
    0           <<< end BLOCK entity
    ENDBLK
    0           <<< end of BLOCKS section
    ENDSEC

Block Definitions in DXF R2000+
-------------------------------

The overall organization in the BLOCKS sections remains the same, but additional
tags in the BLOCK entity, have to be maintained.

Especially the concept of ownership is important. Since DXF R13 every graphic
entity is associated to a specific layout and a BLOCK definition is also a
layout. So all entities in the BLOCK definition, including the BLOCK and the
ENDBLK entities, have an owner tag :code:`(330, ...)`, which points to a
BLOCK_RECORD entry in the BLOCK_RECORD table. This BLOCK_RECORD is the main
management structure for all layouts and is the real owner of the layout
entities.

As you can see in the chapter about :ref:`Layout Management Structures`, this
concept is also valid for modelspace and paperspace layouts, because these
layouts are also BLOCKS, with the special difference, that the entities of the
modelspace and the `active` paperspace layout are stored in the ENTITIES section.

.. image:: gfx/block_definition.png
    :align: center

.. seealso::

    - :ref:`Tag Structure DXF R13 and later`
    - ezdxf DXF Internals: :ref:`tables_section_internals`
    - DXF Reference: `TABLES Section`_
    - DXF Reference: `BLOCK_RECORD Entity`_


DXF R13 BLOCKS structure:

.. code-block:: none

    0           <<< start of a SECTION
    SECTION
    2           <<< start of BLOCKS section
    BLOCKS
    ...         <<< modelspace and paperspace block definitions not shown,
    ...         <<< see layout management
    0           <<< start of BLOCK definition
    BLOCK
    5           <<< even BLOCK gets a handle now ;)
    23A
    330         <<< owner tag, the owner of a BLOCK is a BLOCK_RECORD in the
    ...         BLOCK_RECORD table
    238
    100         <<< subclass marker
    AcDbEntity
    8           <<< layer of the BLOCK definition
    0
    100         <<< subclass marker
    AcDbBlockBegin
    2           <<< BLOCK name
    ArchTick
    70          <<< flags
    0
    10          <<< base point, x
    0.0
    20          <<< base point, y
    0.0
    30          <<< base point, z
    0.0
    3           <<< second BLOCK name, same as (2, name)
    ArchTick
    1           <<< xref name, if block is an external reference
                <<< empty string!
    0           <<< start of the first entity of the BLOCK
    LWPOLYLINE
    5
    239
    330         <<< owner tag of LWPOLYLINE
    238         <<< handle of the BLOCK_RECORD!
    100
    AcDbEntity
    8
    0
    6
    ByBlock
    62
    0
    100
    AcDbPolyline
    90
    2
    70
    0
    43
    0.15
    10
    -0.5
    20
    -0.5
    10
    0.5
    20
    0.5
    0           <<< ENDBLK entity, marks the end of the BLOCK definition
    ENDBLK
    5           <<< handle
    23B
    330         <<< owner tag, same BLOCK_RECORD as for the BLOCK entity
    238
    100         <<< subclass marker
    AcDbEntity
    8           <<< ENDBLK requires the same layer as the BLOCK entity!
    0
    100         <<< subclass marker
    AcDbBlockEnd
    0           <<< start of the next BLOCK
    BLOCK
    ...
    0
    ENDBLK
    ...
    0           <<< end of the BLOCKS section
    ENDSEC


DXF R13 BLOCK_RECORD structure:

.. code-block:: none

    0           <<< start of a SECTION
    SECTION
    2           <<< start of TABLES section
    TABLES
    0           <<< start of a TABLE
    TABLE
    2           <<< start of the BLOCK_RECORD table
    BLOCK_RECORD
    5           <<< handle of the table
    1
    330         <<< owner tag of the table
    0           <<< is always #0
    100         <<< subclass marker
    AcDbSymbolTable
    70          <<< count of table entries, not reliable
    4
    0           <<< start of first BLOCK_RECORD entry
    BLOCK_RECORD
    5           <<< handle of BLOCK_RECORD, in ezdxf often referred to as "layout key"
    1F
    330         <<< owner of the BLOCK_RECORD is the BLOCK_RECORD table
    1
    100         <<< subclass marker
    AcDbSymbolTableRecord
    100         <<< subclass marker
    AcDbBlockTableRecord
    2           <<< name of the BLOCK or LAYOUT
    *Model_Space
    340         <<< pointer to the associated LAYOUT object
    4AF
    70          <<< AC1021 (R2007) block insertion units
    0
    280         <<< AC1021 (R2007) block explodability
    1
    281         <<< AC1021 (R2007) block scalability
    0

    ...         <<< paperspace not shown
    ...
    0           <<< next BLOCK_RECORD
    BLOCK_RECORD
    5           <<< handle of BLOCK_RECORD, in ezdxf often referred to as "layout key"
    238
    330         <<< owner of the BLOCK_RECORD is the BLOCK_RECORD table
    1
    100         <<< subclass marker
    AcDbSymbolTableRecord
    100         <<< subclass marker
    AcDbBlockTableRecord
    2           <<< name of the BLOCK
    ArchTick
    340         <<< pointer to the associated LAYOUT object
    0           <<< #0, because BLOCK doesn't have an associated LAYOUT object
    70          <<< AC1021 (R2007) block insertion units
    0
    280         <<< AC1021 (R2007) block explodability
    1
    281         <<< AC1021 (R2007) block scalability
    0
    0           <<< end of BLOCK_RECORD table
    ENDTAB
    0           <<< next TABLE
    TABLE
    ...
    0
    ENDTAB
    0           <<< end of TABLES section
    ENDESC

.. _BLOCKS Section: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-1D14A213-5E4D-4EA6-A6B5-8709EB925D01

.. _BLOCK Entity: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-66D32572-005A-4E23-8B8B-8726E8C14302

.. _ENDBLK Entity: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-27F7CC8A-E340-4C7F-A77F-5AF139AD502D

.. _INSERT Entity: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-28FA4CFB-9D5E-4880-9F11-36C97578252F

.. _TABLES Section: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-A9FD9590-C97B-4E41-9F26-BD82C34A4F9F

.. _BLOCK_RECORD Entity: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-A1FD1934-7EF5-4D35-A4B0-F8AE54A9A20A