Tutorial for Diameter Dimensions¶
Please read the Tutorial for Radius Dimensions before, if you haven’t.
This is a repetition of the radius tutorial, just with diameter dimensions.
import ezdxf
# setup=True setups the default dimension styles
doc = ezdxf.new('R2010', setup=True)
msp = doc.modelspace() # add new dimension entities to the modelspace
msp.add_circle((0, 0), radius=3) # add a CIRCLE entity, not required
# add default diameter dimension, measurement text is located outside
dim = msp.add_diameter_dim(center=(0, 0), radius=3, angle=45, dimstyle='EZ_RADIUS')
dim.render()
doc.saveas('diameter_dimension.dxf')
The example above creates a 45 degrees slanted diameter Dimension
entity, the default dimension
style 'EZ_RADIUS'
(same as for radius dimensions) is defined as 1 drawing unit is 1m in reality, drawing scale 1:100
and the length factor is 100, which creates a measurement text in cm, the default location for the measurement text is
outside of the circle.
The center point defines the the center of the circle but there doesn’t have to exist a circle entity, radius defines the circle radius and angle defines the slope of the dimension line, it is also possible to define the circle by a measurement point mpoint on the circle.
The return value dim is not a dimension entity, instead a DimStyleOverride
object is
returned, the dimension entity is stored as dim.dimension.
Placing Measurement Text¶
There are different predefined DIMSTYLES to achieve various text placing locations.
DIMSTYLE 'EZ_RADIUS'
settings are: 1 drawing unit is 1m, scale 1:100, length_factor is 100 which creates
measurement text in cm, and a closed filled arrow with size 0.25 is used.
Note
Not all possibles features of DIMSTYLE are supported and especially for diameter dimension there are less features supported as for linear dimension because of the lack of good documentation.
See also
Graphical reference of many DIMVARS and some advanced information: DIMSTYLE Table
Source code file standards.py shows how to create your own DIMSTYLES.
dimension_diameter.py for diameter dimension examples.
Default Text Locations Outside¶
'EZ_RADIUS'
default settings for to place text outside:
tmove |
|
dimtad |
|
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, angle=45,
dimstyle='EZ_RADIUS')
dim.render() # required, but not shown in the following examples

To force text outside horizontal set dimtoh
to 1
:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, angle=45,
dimstyle='EZ_RADIUS',
override={'dimtoh': 1}
)

Default Text Locations Inside¶
DIMSTYLE 'EZ_RADIUS_INSIDE'
can be used to place the dimension text inside the circle at a default
location. Default DIMSTYLE settings are: 1 drawing unit is 1m, scale 1:100, length_factor is 100 which creates
measurement text in cm, and a closed filled arrow with size 0.25 is used.
'EZ_RADIUS_INSIDE'
default settings:
tmove |
|
dimtix |
|
dimatfit |
|
dimtad |
|
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, angle=45,
dimstyle='EZ_RADIUS_INSIDE'
)

To force text inside horizontal set dimtih
to 1
:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, angle=45,
dimstyle='EZ_RADIUS_INSIDE',
override={'dimtih': 1}
)

User Defined Text Locations¶
Beside the default location it is always possible to override the text location by a user defined location. This
location also determines the angle of the dimension line and overrides the argument angle. For user defined locations
it is not necessary to force text inside (dimtix=1
), because the location of the text is explicit given,
therefore the DIMSTYLE 'EZ_RADIUS'
can be used for all this examples.
User defined location outside of the circle:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, location=(4, 4),
dimstyle='EZ_RADIUS'
)

User defined location outside of the circle and forced horizontal text:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, location=(4, 4),
dimstyle='EZ_RADIUS',
override={'dimtoh': 1}
)

User defined location inside of the circle:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, location=(1, 1),
dimstyle='EZ_RADIUS'
)

User defined location inside of the circle and forced horizontal text:
dim = msp.add_diameter_dim(center=(0, 0), radius=2.5, location=(1, 1),
dimstyle='EZ_RADIUS',
override={'dimtih': 1},
)

Center Mark/Lines¶
See Radius Dimension Tutorial: Center Mark/Lines
Overriding Measurement Text¶
See Linear Dimension Tutorial: Overriding Measurement Text
Measurement Text Formatting and Styling¶
See Linear Dimension Tutorial: Measurement Text Formatting and Styling