The MPOLYGON entity is not a core DXF entity and is not supported by all CAD
applications and DXF libraries.
MPolygon class is very similar to the
Hatch class with
small differences in the supported features and DXF attributes.
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).
The MPOLYGON supports
ezdxf.entities.Gradient settings like HATCH
for DXF R2004 and newer. 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||Common graphical DXF attributes|
|Required DXF version||DXF R2000 (
Pattern name as string
1 solid fill, better use:
0 pattern fill, better use:
(search AutoCAD help for more information)
0 user 1 predefined 2 custom
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)
set_pattern_definition(lines: Sequence[T_co], factor: float = 1, angle: float = 0) → None¶
Setup pattern definition by a list of definition lines and the definition line is a 4-tuple (angle, base_point, offset, dash_length_items). The pattern definition should be designed for a pattern scale factor of 1 and a pattern rotation angle of 0.
- angle: line angle in degrees
- base-point: (x, y) tuple
- offset: (dx, dy) tuple
- 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 scale factor
- angle – rotation angle in degrees
set_pattern_scale(scale: float) → None¶
Sets the pattern scale factor and scales the pattern definition.
The method always starts from the original base scale, the
set_pattern_scale(1)call resets the pattern scale to the original appearance as defined by the pattern designer, but only if the pattern attribute
dxf.pattern_scalerepresents the actual scale, it cannot restore the original pattern scale from the pattern definition itself.
Parameters: scale – pattern scale factor
set_pattern_angle(angle: float) → None¶
Sets the pattern rotation angle and rotates the pattern definition.
The method always starts from the original base rotation of 0, the
set_pattern_angle(0)call resets the pattern rotation angle to the original appearance as defined by the pattern designer, but only if the pattern attribute
dxf.pattern_anglerepresents the actual pattern rotation, it cannot restore the original rotation angle from the pattern definition itself.
Parameters: angle – pattern 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¶
Sets the pattern fill mode and removes all gradient related data.
The pattern definition should be designed for a scale factor 1 and a rotation angle of 0 degrees. The 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 – pattern rotation angle in degrees
- scale – pattern scale factor
- 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],
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¶
Sets the gradient fill mode and removes all pattern fill related data, requires DXF R2004 or newer. A gradient filled hatch is also a solid filled hatch.
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”
transform(m: ezdxf.math._matrix44.Matrix44) → ezdxf.entities.polygon.DXFPolygon¶
Transform entity by transformation matrix m inplace.