0
# Entities
1
2
Complete set of entity classes for all DXF entity types, from basic geometric primitives to complex specialized entities. All entities inherit from base classes that provide common functionality for attribute management, transformation, and layout placement.
3
4
## Capabilities
5
6
### Basic Geometric Entities
7
8
Fundamental 2D and 3D geometric primitives that form the building blocks of CAD drawings.
9
10
```python { .api }
11
class Line(DXFGraphic):
12
"""Line entity connecting two points"""
13
14
@property
15
def start(self) -> Vec3:
16
"""Start point of line"""
17
18
@property
19
def end(self) -> Vec3:
20
"""End point of line"""
21
22
def transform(self, matrix: Matrix44): ...
23
24
class Point(DXFGraphic):
25
"""Point entity with location and optional thickness"""
26
27
@property
28
def location(self) -> Vec3:
29
"""Point location"""
30
31
class Circle(DXFGraphic):
32
"""Circle entity with center and radius"""
33
34
@property
35
def center(self) -> Vec3:
36
"""Circle center point"""
37
38
@property
39
def radius(self) -> float:
40
"""Circle radius"""
41
42
class Arc(DXFGraphic):
43
"""Circular arc entity"""
44
45
@property
46
def center(self) -> Vec3:
47
"""Arc center point"""
48
49
@property
50
def radius(self) -> float:
51
"""Arc radius"""
52
53
@property
54
def start_angle(self) -> float:
55
"""Start angle in degrees"""
56
57
@property
58
def end_angle(self) -> float:
59
"""End angle in degrees"""
60
```
61
62
Usage examples:
63
```python
64
import ezdxf
65
from ezdxf.math import Vec3
66
67
doc = ezdxf.new()
68
msp = doc.modelspace()
69
70
# Create basic entities
71
line = msp.add_line(start=(0, 0), end=(10, 5))
72
circle = msp.add_circle(center=(5, 5), radius=2.5)
73
arc = msp.add_arc(center=(0, 0), radius=3, start_angle=0, end_angle=90)
74
75
# Access and modify properties
76
print(f"Line length: {line.start.distance(line.end)}")
77
circle.radius = 3.0
78
arc.end_angle = 180
79
```
80
81
### Text Entities
82
83
Text rendering entities supporting single-line and multi-line text with rich formatting capabilities.
84
85
```python { .api }
86
class Text(DXFGraphic):
87
"""Single-line text entity"""
88
89
@property
90
def text(self) -> str:
91
"""Text content"""
92
93
@property
94
def insert(self) -> Vec3:
95
"""Text insertion point"""
96
97
@property
98
def height(self) -> float:
99
"""Text height"""
100
101
def set_placement(self, insert: Vec3, align: str = None): ...
102
103
class MText(DXFGraphic):
104
"""Multi-line text entity with rich formatting"""
105
106
@property
107
def text(self) -> str:
108
"""Raw MTEXT content with formatting codes"""
109
110
@property
111
def insert(self) -> Vec3:
112
"""Text insertion point"""
113
114
@property
115
def char_height(self) -> float:
116
"""Character height"""
117
118
@property
119
def width(self) -> float:
120
"""Text box width"""
121
122
def plain_text(self) -> str:
123
"""Get text content without formatting codes"""
124
```
125
126
Usage examples:
127
```python
128
# Single-line text
129
text = msp.add_text("Hello World", height=2.5)
130
text.set_placement((10, 10))
131
132
# Multi-line text with formatting
133
mtext_content = "{\\fArial|b1|i1;Bold Italic Arial}\\P{\\fTimes;Regular Times}"
134
mtext = msp.add_mtext(mtext_content, dxfattribs={
135
'char_height': 2.0,
136
'width': 50.0
137
})
138
```
139
140
### Polyline Entities
141
142
Linear entities composed of multiple connected segments, supporting 2D/3D polylines with optional bulge values for arc segments.
143
144
```python { .api }
145
class Polyline(DXFGraphic):
146
"""2D/3D polyline with vertices and optional bulge values"""
147
148
def append_vertex(self, location, dxfattribs: dict = None): ...
149
def insert_vertex(self, index: int, location, dxfattribs: dict = None): ...
150
def delete_vertex(self, index: int): ...
151
152
@property
153
def vertices(self):
154
"""Vertex entities"""
155
156
@property
157
def is_closed(self) -> bool:
158
"""True if polyline is closed"""
159
160
class LWPolyline(DXFGraphic):
161
"""Lightweight 2D polyline (optimized format)"""
162
163
def append(self, point, format: str = 'xyseb'): ...
164
def insert(self, index: int, point, format: str = 'xyseb'): ...
165
def __delitem__(self, index: int): ...
166
167
@property
168
def vertices(self) -> List:
169
"""List of vertex data (x, y, start_width, end_width, bulge)"""
170
171
@property
172
def is_closed(self) -> bool:
173
"""True if polyline is closed"""
174
```
175
176
Usage examples:
177
```python
178
from ezdxf.math import Vec3
179
180
# 3D polyline
181
points_3d = [Vec3(0, 0, 0), Vec3(10, 0, 5), Vec3(10, 10, 5), Vec3(0, 10, 0)]
182
polyline_3d = msp.add_polyline3d(points_3d)
183
polyline_3d.close() # Close the polyline
184
185
# Lightweight 2D polyline with bulge (arc segment)
186
lwpolyline = msp.add_lwpolyline([(0, 0), (10, 0), (10, 10)])
187
lwpolyline.append((0, 10), format='xyb') # Add point with bulge
188
lwpolyline.close()
189
```
190
191
### Advanced Curve Entities
192
193
Sophisticated curve entities including ellipses, splines, and infinite lines.
194
195
```python { .api }
196
class Ellipse(DXFGraphic):
197
"""Ellipse entity with center, major/minor axes"""
198
199
@property
200
def center(self) -> Vec3:
201
"""Ellipse center"""
202
203
@property
204
def major_axis(self) -> Vec3:
205
"""Major axis vector"""
206
207
@property
208
def minor_axis(self) -> Vec3:
209
"""Minor axis vector"""
210
211
@property
212
def ratio(self) -> float:
213
"""Minor to major axis ratio"""
214
215
class Spline(DXFGraphic):
216
"""NURBS spline curve"""
217
218
@property
219
def degree(self) -> int:
220
"""Spline degree"""
221
222
@property
223
def control_points(self) -> List[Vec3]:
224
"""Control point coordinates"""
225
226
@property
227
def knots(self) -> List[float]:
228
"""Knot vector"""
229
230
@property
231
def weights(self) -> List[float]:
232
"""Control point weights (for rational splines)"""
233
234
class XLine(DXFGraphic):
235
"""Infinite line (construction line)"""
236
237
@property
238
def start(self) -> Vec3:
239
"""Point on the line"""
240
241
@property
242
def unit_vector(self) -> Vec3:
243
"""Unit direction vector"""
244
245
class Ray(DXFGraphic):
246
"""Ray (semi-infinite line)"""
247
248
@property
249
def start(self) -> Vec3:
250
"""Ray start point"""
251
252
@property
253
def unit_vector(self) -> Vec3:
254
"""Unit direction vector"""
255
```
256
257
### Hatch and Fill Entities
258
259
Complex fill entities supporting patterns, solid fills, and gradient fills with boundary path definitions.
260
261
```python { .api }
262
class Hatch(DXFGraphic):
263
"""Hatch entity with boundary paths and fill patterns"""
264
265
@property
266
def pattern_name(self) -> str:
267
"""Hatch pattern name"""
268
269
@property
270
def solid_fill(self) -> bool:
271
"""True if solid fill"""
272
273
@property
274
def pattern_type(self) -> int:
275
"""Pattern type (0=user, 1=predefined, 2=custom)"""
276
277
@property
278
def paths(self):
279
"""Boundary path definitions"""
280
281
@property
282
def gradient(self):
283
"""Gradient fill definition"""
284
285
def set_solid_fill(self, color: int = 256): ...
286
def set_pattern_fill(self, name: str, color: int = 256, angle: float = 0, scale: float = 1): ...
287
def set_gradient(self, color1: int, color2: int, rotation: float = 0): ...
288
289
class MPolygon(DXFGraphic):
290
"""Multi-polygon entity with holes and islands"""
291
292
@property
293
def paths(self):
294
"""Polygon boundary paths"""
295
296
@property
297
def fill_color(self) -> int:
298
"""Fill color index"""
299
```
300
301
### Block and Insert Entities
302
303
Block definition and insertion entities for reusable content and hierarchical drawing organization.
304
305
```python { .api }
306
class Insert(DXFGraphic):
307
"""Block reference (insertion) entity"""
308
309
@property
310
def name(self) -> str:
311
"""Block name"""
312
313
@property
314
def insert(self) -> Vec3:
315
"""Insertion point"""
316
317
@property
318
def xscale(self) -> float:
319
"""X-axis scale factor"""
320
321
@property
322
def yscale(self) -> float:
323
"""Y-axis scale factor"""
324
325
@property
326
def zscale(self) -> float:
327
"""Z-axis scale factor"""
328
329
@property
330
def rotation(self) -> float:
331
"""Rotation angle in degrees"""
332
333
def explode(self) -> List[DXFEntity]:
334
"""Explode block insert into individual entities"""
335
336
class Block(DXFEntity):
337
"""Block definition start marker"""
338
339
@property
340
def name(self) -> str:
341
"""Block name"""
342
343
@property
344
def base_point(self) -> Vec3:
345
"""Block base point"""
346
347
class EndBlk(DXFEntity):
348
"""Block definition end marker"""
349
```
350
351
### Dimension Entities
352
353
Comprehensive dimensioning entities for annotating drawings with measurements and geometric relationships.
354
355
```python { .api }
356
class Dimension(DXFGraphic):
357
"""Base class for dimension entities"""
358
359
@property
360
def dimstyle(self) -> str:
361
"""Dimension style name"""
362
363
@property
364
def actual_measurement(self) -> float:
365
"""Actual measured value"""
366
367
def render(self) -> List[DXFEntity]:
368
"""Render dimension to basic entities"""
369
370
# Specific dimension types inherit from Dimension
371
class LinearDimension(Dimension): ...
372
class AlignedDimension(Dimension): ...
373
class AngularDimension(Dimension): ...
374
class RadialDimension(Dimension): ...
375
class DiametricDimension(Dimension): ...
376
class OrdinateDimension(Dimension): ...
377
```
378
379
### 3D Solid and Surface Entities
380
381
Advanced 3D modeling entities including ACIS solids and parametric surfaces.
382
383
```python { .api }
384
class Solid3d(DXFGraphic):
385
"""3D solid entity (ACIS-based)"""
386
387
@property
388
def acis_data(self) -> bytes:
389
"""ACIS solid data"""
390
391
class Surface(DXFGraphic):
392
"""3D surface entity"""
393
394
@property
395
def u_isolines(self) -> int:
396
"""Number of U-direction isolines"""
397
398
@property
399
def v_isolines(self) -> int:
400
"""Number of V-direction isolines"""
401
402
class Mesh(DXFGraphic):
403
"""Subdivision mesh entity"""
404
405
@property
406
def vertices(self) -> List[Vec3]:
407
"""Mesh vertex coordinates"""
408
409
@property
410
def faces(self) -> List[List[int]]:
411
"""Face definitions as vertex indices"""
412
413
@property
414
def edges(self) -> List[List[int]]:
415
"""Edge definitions as vertex index pairs"""
416
```
417
418
## Entity Base Classes
419
420
```python { .api }
421
class DXFEntity:
422
"""Base class for all DXF entities"""
423
424
@property
425
def dxftype(self) -> str:
426
"""DXF entity type name"""
427
428
@property
429
def handle(self) -> str:
430
"""Unique entity handle"""
431
432
@property
433
def owner(self) -> str:
434
"""Handle of owning object"""
435
436
def destroy(self): ...
437
def copy(self) -> 'DXFEntity': ...
438
439
class DXFGraphic(DXFEntity):
440
"""Base class for graphical entities that can be placed in layouts"""
441
442
@property
443
def layer(self) -> str:
444
"""Entity layer name"""
445
446
@property
447
def color(self) -> int:
448
"""Entity color (ACI or RGB)"""
449
450
@property
451
def linetype(self) -> str:
452
"""Entity linetype name"""
453
454
@property
455
def lineweight(self) -> int:
456
"""Entity lineweight"""
457
458
def transform(self, matrix: Matrix44): ...
459
def translate(self, dx: float, dy: float, dz: float): ...
460
def scale(self, sx: float, sy: float, sz: float): ...
461
def rotate_axis(self, axis: Vec3, angle: float): ...
462
463
class DXFObject(DXFEntity):
464
"""Base class for non-graphical DXF objects"""
465
```
466
467
## Entity Factory Functions
468
469
Layout classes provide factory methods for creating and adding entities:
470
471
```python { .api }
472
# These methods are available on Layout, Modelspace, and Paperspace classes
473
def add_line(self, start, end, dxfattribs: dict = None) -> Line: ...
474
def add_circle(self, center, radius: float, dxfattribs: dict = None) -> Circle: ...
475
def add_arc(self, center, radius: float, start_angle: float, end_angle: float,
476
dxfattribs: dict = None) -> Arc: ...
477
def add_text(self, text: str, dxfattribs: dict = None) -> Text: ...
478
def add_mtext(self, text: str, dxfattribs: dict = None) -> MText: ...
479
def add_lwpolyline(self, points, format: str = 'xy', dxfattribs: dict = None) -> LWPolyline: ...
480
def add_polyline3d(self, points, dxfattribs: dict = None) -> Polyline: ...
481
def add_ellipse(self, center, major_axis, ratio: float = 1, start_param: float = 0,
482
end_param: float = 2*pi, dxfattribs: dict = None) -> Ellipse: ...
483
def add_spline(self, control_points, degree: int = 3, dxfattribs: dict = None) -> Spline: ...
484
def add_hatch(self, color: int = 256, dxfattribs: dict = None) -> Hatch: ...
485
def add_insert(self, name: str, insert = (0, 0), dxfattribs: dict = None) -> Insert: ...
486
```