Tutorial for Simple DXF Entities

These are basic graphical entities located in an entity space like the modelspace or a block definition and only support the common graphical attributes.

The entities in the following examples are always placed in the xy-plane of the WCS aka the 2D drawing space. Some of these entities can only be placed outside the xy-plane in 3D space by utilizing the OCS, but this feature is beyond the scope of this tutorial, for more information about that go to: Tutorial for OCS/UCS Usage.

Prelude to all following examples:

import ezdxf
from ezdxf.gfxattribs import GfxAttribs

doc = ezdxf.new()
doc.layers.new("ENTITY", color=1)
msp = doc.modelspace()
attribs = GfxAttribs(layer="ENTITY")

Point

The Point entity marks a 3D point in the WCS:

point = msp.add_point((10, 10), dxfattribs=attribs)

All Point entities have the same styling stored in the header variable $PDMODE, for more information read the reference of class Point.

See also

Line

The Line entity is a 3D line with a start- and an end point in the WCS:

line = msp.add_line((0, 0), (10, 10), dxfattribs=attribs)

Circle

The Circle entity is an OCS entity defined by a center point and a radius:

circle = msp.add_circle((10, 10), radius=3, dxfattribs=attribs)

Arc

The Arc entity is an OCS entity defined by a center point, a radius a start- and an end angle in degrees:

arc = msp.add_arc((10, 10), radius=3, start_angle=30, end_angle=120, dxfattribs=attribs)

The arc goes always in counter-clockwise orientation around the z-axis more precisely the extrusion vector of OCS, but this is beyond the scope of this tutorial.

The helper class ezdxf.math.ConstructionArc provides constructors to create arcs from different scenarios:

This example creates an arc from point (10, 0) to point (0, 0) passing the point (5, 3):

from ezdxf.math import ConstructionArc

# -x-x-x- snip -x-x-x-

arc = ConstructionArc.from_3p(
    start_point=(10, 0), end_point=(0, 0), def_point=(5, 3)
)
arc.add_to_layout(msp, dxfattribs=attribs)

Ellipse

The Ellipse entity requires DXF R2000 or newer and is a true WCS entity. The ellipse is defined by a center point, a vector for the major axis, the ratio between major- and minor axis and the start- and end parameter in radians:

ellipse = msp.add_ellipse(
    (10, 10), major_axis=(5, 0), ratio=0.5, start_param=0, end_param=math.pi, dxfattribs=attribs
)

When placed in 3D space the extrusion vector defines the normal vector of the ellipse plane and the minor axis is the extrusion vector cross the major axis.

Further Tutorials