The MPOLYGON entity is not a core DXF entity and is not supported by every CAD application or DXF library.
The boundary paths of the MPOLYGON are visible and use the graphical DXF
attributes of the main entity like
dxf.linetype and so on.
The solid filling is only visible if the attribute
dxf.solid_fill is 1,
the color of the solid fill is defined by
dxf.fill_color as AutoCAD Color Index (ACI).
ezdxf.entities.Gradient settings like HATCH
for DXF R2004+. This feature is used by method
to set a solid RGB fill color as linear gradient, this disables pattern fill
The MPOLYGON does not support associated source path entities, because the MPOLYGON also represents the boundary paths as visible graphical objects.
Hatch patterns are supported, but the hatch style tag is not supported, the
default hatch style is
ezdxf.const.HATCH_STYLE_NESTED and the style
flags of the boundary paths are ignored.
Background color for pattern fillings is supported, set background color
MPolygon.bgcolor as RGB tuple.
Background RGB fill color for solid fill and pattern fill is set differently!
Autodesk products do support polyline paths including bulges.
An example for edge paths as boundary paths is not available or edge paths
are not supported. Ezdxf does not export MPOLYGON entities including
edge paths! The
BoundaryPaths.edge_to_polyline_paths() method converts
all edge paths to simple polyline paths with approximated curves, this
conversion has to be done explicit.
For more information see the
Inherited DXF attributes
Required DXF version
DXF R2000 (
- class ezdxf.entities.MPolygon¶
Pattern name as string
solid fill, better use:
pattern fill, better use:
(search AutoCAD help for more information)
Actual pattern angle in degrees (float). Changing this value does not rotate the pattern, use
set_pattern_angle()for this task.
Actual pattern scaling factor (float). Changing this value does not scale the pattern use
set_pattern_scale()for this task.
1 = double pattern size else 0. (int)
- property has_solid_fill: bool¶
Trueif entity has a solid fill. (read only)
- property has_pattern_fill: bool¶
Trueif entity has a pattern fill. (read only)
- property has_gradient_data: bool¶
Trueif entity has a gradient fill. A hatch with gradient fill has also a solid fill. (read only)
- property bgcolor: Optional[Tuple[int, int, int]]¶
Set pattern fill background color as (r, g, b)-tuple, rgb values in the range [0, 255] (read/write/del)
r, g, b = entity.bgcolor # get pattern fill background color entity.bgcolor = (10, 20, 30) # set pattern fill background color del entity.bgcolor # delete pattern fill background color
- set_pattern_definition(lines: Sequence, factor: float = 1, angle: float = 0) None ¶
Setup pattern definition by a list of definition lines and a definition line is a 4-tuple (angle, base_point, offset, dash_length_items), the pattern definition should be designed for scaling factor 1 and angle 0.
angle: line angle in degrees
base-point: 2-tuple (x, y)
offset: 2-tuple (dx, dy)
dash_length_items: list of dash items (item > 0 is a line, item < 0 is a gap and item == 0.0 is a point)
lines – list of definition lines
factor – pattern scaling factor
angle – rotation angle in degrees
- set_pattern_scale(scale: float) None ¶
Set scaling of pattern definition to scale.
Starts always from the original base scaling,
set_pattern_scale(1)reset the pattern scaling to the original appearance as defined by the pattern designer, but only if the pattern attribute
dxf.pattern_scalerepresents the actual scaling, it is not possible to recreate the original pattern scaling from the pattern definition itself.
scale – pattern scaling factor
- set_pattern_angle(angle: float) None ¶
Set rotation of pattern definition to angle in degrees.
Starts always from the original base rotation 0,
set_pattern_angle(0)reset the pattern rotation to the original appearance as defined by the pattern designer, but only if the pattern attribute
dxf.pattern_anglerepresents the actual rotation, it is not possible to recreate the original rotation from the pattern definition itself.
angle – rotation angle in degrees
- set_solid_fill(color: int = 7, style: int = 1, rgb: Optional[RGB] = None)¶
MPolygonto solid fill mode and removes all gradient and pattern fill related data.
color – AutoCAD Color Index (ACI), (0 = BYBLOCK; 256 = BYLAYER)
style – hatch style is not supported by MPOLYGON, just for symmetry to HATCH
rgb – true color value as (r, g, b)-tuple - has higher priority than color. True color support requires DXF R2004+
- set_pattern_fill(name: str, color: int = 7, angle: float = 0.0, scale: float = 1.0, double: int = 0, style: int = 1, pattern_type: int = 1, definition=None) None ¶
MPolygonto pattern fill mode. Removes all gradient related data. The pattern definition should be designed for scaling factor 1. Predefined hatch pattern like “ANSI33” are scaled according to the HEADER variable $MEASUREMENT for ISO measurement (m, cm, … ), or imperial units (in, ft, …), this replicates the behavior of BricsCAD.
name – pattern name as string
color – pattern color as AutoCAD Color Index (ACI)
angle – angle of pattern fill in degrees
scale – pattern scaling as float
double – double size flag
style – hatch style (0 = normal; 1 = outer; 2 = ignore)
pattern_type – pattern type (0 = user-defined; 1 = predefined; 2 = custom)
definition – list of definition lines and a definition line is a 4-tuple [angle, base_point, offset, dash_length_items], see
- set_gradient(color1: Tuple[int, int, int] = (0, 0, 0), color2: Tuple[int, int, int] = (255, 255, 255), rotation: float = 0.0, centered: float = 0.0, one_color: int = 0, tint: float = 0.0, name: str = 'LINEAR') None ¶
Valid gradient type names are:
color1 – (r, g, b)-tuple for first color, rgb values as int in the range [0, 255]
color2 – (r, g, b)-tuple for second color, rgb values as int in the range [0, 255]
rotation – rotation angle in degrees
centered – determines whether the gradient is centered or not
one_color – 1 for gradient from color1 to tinted color1
tint – determines the tinted target color1 for a one color gradient. (valid range 0.0 to 1.0)
name – name of gradient type, default “LINEAR”