Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_attribs(additional: dict = None) -> DXFAttributes:
dxfattribs = {
'handle': DXFAttr(5),
'layer': DXFAttr(8, default='0'), # layer name as string, mandatory according to the DXF Reference
'linetype': DXFAttr(6, default='BYLAYER'), # linetype as string, special names BYLAYER/BYBLOCK
'color': DXFAttr(62, default=256), # dxf color index, 0 .. BYBLOCK, 256 .. BYLAYER
'thickness': DXFAttr(39, default=0), # thickness of 2D elements
'paperspace': DXFAttr(67, default=0), # 0=modelspace; 1=paperspace
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0.0, 0.0, 1.0)), # Z-axis of OCS (Object-Coordinate-System)
}
if additional is not None:
dxfattribs.update(additional)
return DXFAttributes(DefSubclass(None, dxfattribs))
10
0.0
20
0.0
30
0.0
11
1.0
21
1.0
31
1.0
"""
line_subclass = DefSubclass('AcDbLine', {
'start': DXFAttr(10, xtype=XType.any_point),
'end': DXFAttr(11, xtype=XType.any_point),
'thickness': DXFAttr(39, default=0),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0.0, 0.0, 1.0)),
})
class Line(r12graphics.Line, ModernGraphicEntityExtension):
__slots__ = ()
TEMPLATE = ExtendedTags.from_text(_LINETEMPLATE)
DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, line_subclass)
_POINT_TPL = """0
POINT
5
0
# Text annotation height
'text_height': DXFAttr(40, default=1, optional=True),
# Text annotation width
'text_width': DXFAttr(41, default=0, optional=True),
# 76: Number of vertices in leader (ignored for OPEN)
# 10, 20, 30: Vertex coordinates (one entry for each vertex)
# Color to use if leader's DIMCLRD = BYBLOCK
'block_color': DXFAttr(77, default=7, optional=True),
# Hard reference to associated annotation (mtext, tolerance, or insert entity)
'annotation_handle': DXFAttr(340, default='0', optional=True),
'normal_vector': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
# 'horizontal' direction for leader
'horizontal_direction': DXFAttr(211, xtype=XType.point3d, default=Vector(1, 0, 0), optional=True),
# Offset of last leader vertex from block reference insertion point
'leader_offset_block_ref': DXFAttr(212, xtype=XType.point3d, default=Vector(0, 0, 0), optional=True),
# Offset of last leader vertex from annotation placement point
'leader_offset_annotation_placement': DXFAttr(213, xtype=XType.point3d, default=Vector(0, 0, 0), optional=True),
# Xdata belonging to the application ID "ACAD" follows a leader entity if any dimension overrides
# have been applied to this entity. See Dimension Style Overrides.
})
@register_entity
LWPointType = Tuple[float, float, float, float, float]
FORMAT_CODES = frozenset('xysebv')
DEFAULT_FORMAT = 'xyseb'
LWPOINTCODES = (10, 20, 40, 41, 42)
# Order doesn't matter, not valid for AutoCAD:
# If tag 90 is not the first TAG, AutoCAD does not close the polyline, when the `close` flag is set.
acdb_lwpolyline = DefSubclass('AcDbPolyline', {
'count': DXFAttr(90, xtype=XType.callback, getter='__len__'),
# always return actual length and set tag 90
'elevation': DXFAttr(38, default=0, optional=True),
'thickness': DXFAttr(39, default=0, optional=True),
'flags': DXFAttr(70, default=0),
'const_width': DXFAttr(43, optional=True),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
# 10, 20 : Vertex x, y
# 91: vertex identifier ???
# 40, 41, 42: start width, end width, bulge
})
@register_entity
class LWPolyline(DXFGraphic):
""" DXF LWPOLYLINE entity """
DXFTYPE = 'LWPOLYLINE'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_lwpolyline)
MIN_DXF_VERSION_FOR_EXPORT = DXF2000
def __init__(self, doc: 'Drawing' = None):
super().__init__(doc)
self.lwpoints = LWPolylinePoints()
# 1 = Top left; 2 = Top center; 3 = Top right
# 4 = Middle left; 5 = Middle center; 6 = Middle right
# 7 = Bottom left; 8 = Bottom center; 9 = Bottom right
'attachment_point': DXFAttr(71, default=1),
# 1 = Left to right
# 3 = Top to bottom
# 5 = By style (the flow direction is inherited from the associated text style)
'flow_direction': DXFAttr(72, default=1, optional=True),
# code 1: text
# code 3: additional text (optional)
'style': DXFAttr(7, default='Standard', optional=True), # text style name
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
# x-axis direction vector (in WCS)
# If rotation and text_direction are present, text_direction wins
'text_direction': DXFAttr(11, xtype=XType.point3d, default=Vector(1, 0, 0), optional=True),
# Horizontal width of the characters that make up the mtext entity.
# This value will always be equal to or less than the value of *width*, (read-only, ignored if supplied)
'rect_width': DXFAttr(42, optional=True),
# vertical height of the mtext entity (read-only, ignored if supplied)
'rect_height': DXFAttr(43, optional=True),
# in degrees (circle=360 deg) - error in DXF reference, which says radians
'rotation': DXFAttr(50, default=0, optional=True),
# 1 = At least (taller characters will override)
74
0
"""
spline_subclass = DefSubclass('AcDbSpline', {
'flags': DXFAttr(70, default=0),
'degree': DXFAttr(71),
'n_knots': DXFAttr(72, xtype=XType.callback, getter='knot_value_count'),
'n_control_points': DXFAttr(73, xtype=XType.callback, getter='control_point_count'),
'n_fit_points': DXFAttr(74, xtype=XType.callback, getter='fit_point_count'),
'knot_tolerance': DXFAttr(42, default=1e-10),
'control_point_tolerance': DXFAttr(43, default=1e-10),
'fit_tolerance': DXFAttr(44, default=1e-10),
'start_tangent': DXFAttr(12, xtype=XType.point3d),
'end_tangent': DXFAttr(13, xtype=XType.point3d),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0.0, 0.0, 1.0)),
# 10: Control points (in WCS); one entry per control point
# 11: Fit points (in WCS); one entry per fit point
# 40: Knot value (one entry per knot)
# 41: Weight (if not 1); with multiple group pairs, they are present if all are not 1
})
class Spline(ModernGraphicEntity):
__slots__ = ()
TEMPLATE = tag_processor(ExtendedTags.from_text(_SPLINE_TPL))
DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, spline_subclass)
CLOSED = 1 # closed b-spline
PERIODIC = 2 # uniform b-spline
RATIONAL = 4 # rational b-spline
PLANAR = 8 # all spline points in a plane, don't read or set this bit, just ignore like AutoCAD
LINEAR = 16 # always set with PLANAR, don't read or set this bit, just ignore like AutoCAD
from ezdxf.math import Vector, Matrix44, NULLVEC, Z_AXIS, ConstructionEllipse
from ezdxf.lldxf.attributes import DXFAttr, DXFAttributes, DefSubclass, XType
from ezdxf.lldxf.const import SUBCLASS_MARKER, DXF2000
from ezdxf.math import ellipse, NULLVEC
from .dxfentity import base_class, SubclassProcessor
from .dxfgfx import DXFGraphic, acdb_entity, add_entity, replace_entity
from .factory import register_entity
from ezdxf.audit import AuditError
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, DXFNamespace, Spline, Auditor
__all__ = ['Ellipse']
acdb_ellipse = DefSubclass('AcDbEllipse', {
'center': DXFAttr(10, xtype=XType.point3d, default=Vector(0, 0, 0)),
'major_axis': DXFAttr(11, xtype=XType.point3d, default=Vector(1, 0, 0)), # relative to the center
# extrusion does not establish an OCS, it is just the normal vector of the ellipse plane.
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0, 0, 1), optional=True),
'ratio': DXFAttr(40, default=1), # has to be in range 1e-6 to 1
'start_param': DXFAttr(41, default=0), # this value is 0.0 for a full ellipse
'end_param': DXFAttr(42, default=math.tau), # this value is 2*pi for a full ellipse
})
HALF_PI = math.pi / 2.0
@register_entity
class Ellipse(DXFGraphic):
""" DXF ELLIPSE entity """
DXFTYPE = 'ELLIPSE'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_ellipse)
from ezdxf.math import Vector
from ezdxf.lldxf.attributes import DXFAttr, DXFAttributes, DefSubclass, XType
from ezdxf.lldxf.const import SUBCLASS_MARKER, DXF2000
from .dxfentity import base_class, SubclassProcessor
from .dxfgfx import DXFGraphic, acdb_entity
from .factory import register_entity
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, DXFNamespace, UCS
__all__ = ['Tolerance']
acdb_tolerance = DefSubclass('AcDbFcf', {
'dimstyle': DXFAttr(3, default='Standard'),
'insert': DXFAttr(10, xtype=XType.point3d, default=Vector(0, 0, 0)), # Insertion point (in WCS)
'content': DXFAttr(1, default=""), # String representing the visual representation of the tolerance
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True), # Extrusion direction
'x_axis_vector': DXFAttr(11, xtype=XType.point3d, default=Vector(1, 0, 0)), # X-axis direction vector (in WCS)
})
@register_entity
class Tolerance(DXFGraphic):
""" DXF TOLERANCE entity """
DXFTYPE = 'TOLERANCE'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_tolerance)
MIN_DXF_VERSION_FOR_EXPORT = DXF2000
def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
dxf = super().load_dxf_attribs(processor)
if processor:
76
1
98
1
10
0.0
20
0.0
"""
# removed tag (code=47, 0.0442352806926743) from Template: pixel size - caused problems in AutoCAD
# default is a solid fil hatch
hatch_subclass = DefSubclass('AcDbHatch', {
'elevation': DXFAttr(10, xtype=XType.point3d, default=(0.0, 0.0, 0.0)),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0.0, 0.0, 1.0)),
'pattern_name': DXFAttr(2, default='SOLID'), # for solid fill
'solid_fill': DXFAttr(70, default=1), # pattern fill = 0
'associative': DXFAttr(71, default=0), # associative flag = 0
'hatch_style': DXFAttr(75, default=const.HATCH_STYLE_OUTERMOST), # 0=normal; 1=outer; 2=ignore
'pattern_type': DXFAttr(76, default=const.HATCH_TYPE_PREDEFINED), # 0=user; 1=predefined; 2=custom???
'pattern_angle': DXFAttr(52, default=0.0), # degrees (360deg = circle)
'pattern_scale': DXFAttr(41, default=1.0),
'pattern_double': DXFAttr(77, default=0), # 0=not double; 1= double
'n_seed_points': DXFAttr(98), # number of seed points
})
GRADIENT_CODES = frozenset([450, 451, 452, 453, 460, 461, 462, 463, 470, 421, 63])
PATH_CODES = frozenset([10, 11, 12, 13, 40, 42, 50, 51, 42, 72, 73, 74, 92, 93, 94, 95, 96, 97, 330])
PATTERN_DEFINITION_LINE_CODES = frozenset((53, 43, 44, 45, 46, 79, 49))
# Created: 09.03.2016
# Copyright (c) 2016-2018, Manfred Moitzi
# License: MIT License
from ezdxf.legacy import dimension
from ezdxf.lldxf.attributes import DXFAttr, DXFAttributes, DefSubclass, XType
from ezdxf.lldxf.const import DXFInternalEzdxfError
from ezdxf.lldxf.tags import Tags
from .graphics import none_subclass, entity_subclass, ModernGraphicEntity, ExtendedTags
dimension_subclass = DefSubclass('AcDbDimension', {
'geometry': DXFAttr(2), # name of pseudo-Block containing the current dimension entity geometry
'dimstyle': DXFAttr(3, default='STANDARD'), # dimension style name
# The dimension style is stored in Drawing.sections.tables.dimstyles,
# shortcut Drawings.dimstyles property
'defpoint': DXFAttr(10, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # definition point for all dimension types
'text_midpoint': DXFAttr(11, xtype=XType.any_point), # midpoint of dimension text
'dimtype': DXFAttr(70, default=0), # Dimension type:
# Values 0–6 are integer values that represent the dimension type.
# Values 32, 64, and 128 are bit values, which are added to the integer values
# (value 32 is always set in R13 and later releases)
# 0 = Rotated, horizontal, or vertical;
# 1 = Aligned
# 2 = Angular;
# 3 = Diameter;
# 4 = Radius
# 5 = Angular 3 point;
# 6 = Ordinate
# 32 = Indicates that the block reference (group code 2) is referenced by this dimension only
# 64 = Ordinate type. This is a bit value (bit 7) used only with integer
# value 6. If set, ordinate is X-type; if not set, ordinate is Y-type
# 128 = This is a bit value (bit 8) added to the other group 70 values if
# the dimension text has been positioned at a user-defined location