Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
30
0.0
11
1.0
21
1.0
31
1.0
"""
class AttributeChecker(DXFEntity):
TEMPLATE = XTEMPLATE
DXFATTRIBS = DXFAttributes(
DefSubclass(None, {
'handle': DXFAttr(5),
'block_record': DXFAttr(330),
}),
DefSubclass('AcDbEntity', {
'paperspace': DXFAttr(67, default=0),
'layer': DXFAttr(8, default='0'),
'linetype': DXFAttr(6, default='BYLAYER'),
'ltscale': DXFAttr(48, default=1.0),
'invisible': DXFAttr(60, default=0),
'color': DXFAttr(62, default=256),
}),
DefSubclass('AcDbLine', {
'start': DXFAttr(10, XType.any_point),
'end': DXFAttr(11, XType.any_point),
'thickness': DXFAttr(39),
'extrusion': DXFAttr(210, XType.point3d),
}))
'paperspace': DXFAttr(67, default=0), # 0 .. modelspace, 1 .. paperspace
'layer': DXFAttr(8, default='0'), # layername as string
'linetype': DXFAttr(6, default='BYLAYER'), # linetype as string, special names BYLAYER/BYBLOCK
'lineweight': DXFAttr(370), # Stored and moved around as a 16-bit integer
# Line weight in mm times 100 (e.g. 0.13mm = 13). Smallest line weight is 13 and biggest line weight is 200, values
# outside this range prevents AutoCAD from loading the file.
# Special values:
# LINEWEIGHT_BYLAYER = -1
# LINEWEIGHT_BYBLOCK = -2
# LINEWEIGHT_DEFAULT = -3
'ltscale': DXFAttr(48, default=1.0), # linetype scale
'invisible': DXFAttr(60, default=0), # invisible .. 1, visible .. 0
'color': DXFAttr(62, default=256), # dxf color index, 0 .. BYBLOCK, 256 .. BYLAYER
'true_color': DXFAttr(420, dxfversion='AC1018'), # true color as 0x00RRGGBB 24-bit value
'color_name': DXFAttr(430, dxfversion='AC1018'), # color name as string
'transparency': DXFAttr(440, dxfversion='AC1018'), # transparency value 0x020000TT 0 = fully transparent / 255 = opaque
'shadow_mode': DXFAttr(284, dxfversion='AC1021'), # shadow_mode
# 0 = Casts and receives shadows
# 1 = Casts shadows
# 2 = Receives shadows
# 3 = Ignores shadows
})
# noinspection PyUnresolvedReferences
class ModernGraphicEntityExtension:
__slots__ = ()
@property
def rgb(self) -> Tuple[int, int, int]:
return int2rgb(self.get_dxf_attrib('true_color'))
'dimtdec': DXFAttr(272),
'dimaltu': DXFAttr(273),
'dimalttd': DXFAttr(274),
'dimaunit': DXFAttr(275),
'dimfrac': DXFAttr(276),
'dimlunit': DXFAttr(277),
'dimdsep': DXFAttr(278),
'dimtmove': DXFAttr(279),
'dimjust': DXFAttr(280),
'dimsd1': DXFAttr(281),
'dimsd2': DXFAttr(282),
'dimtolj': DXFAttr(283),
'dimtzin': DXFAttr(284),
'dimaltz': DXFAttr(285),
'dimalttz': DXFAttr(286),
'dimfit': DXFAttr(287), # obsolete, now use DIMATFIT and DIMTMOVE
'dimupt': DXFAttr(288),
'dimatfit': DXFAttr(289),
'dimfxlon': DXFAttr(290, dxfversion='AC1021'), # undocumented: 1 = fixed extension line length
'dimtxsty_handle': DXFAttr(340), # handle of referenced STYLE entry
# virtual DXF attribute 'dimtxsty': set/get referenced STYLE by name as callback
'dimtxsty': DXFAttr(VIRTUAL_TAG, xtype=XType.callback, getter='get_text_style', setter='set_text_style'),
# virtual DXF attribute 'dimldrblk': set/get referenced STYLE by name as callback
'dimldrblk': DXFAttr(VIRTUAL_TAG, xtype=XType.callback, getter='get_dimldrblk', setter='set_dimldrblk'),
'dimldrblk_handle': DXFAttr(341), # handle of referenced BLOCK_RECORD
'dimblk_handle': DXFAttr(342), # handle of referenced BLOCK_RECORD
'dimblk1_handle': DXFAttr(343), # handle of referenced BLOCK_RECORD
'dimblk2_handle': DXFAttr(344), # handle of referenced BLOCK_RECORD
'dimltype_handle': DXFAttr(345, dxfversion='AC1021'), # handle of linetype for dimension line
# virtual DXF attribute 'dimldtype': set/get referenced LINETYPE by name as callback
'dimltype': DXFAttr(VIRTUAL_TAG,
# -1 = On, but is fully off screen, or is one of the viewports that is not active because the $MAXACTVP count is
# currently being exceeded.
# 0 = Off
# = On and active. The value indicates the order of stacking for the viewports, where 1 is the
# active viewport, 2 is the next, and so forth
'id': DXFAttr(69, default=2),
'view_center_point': DXFAttr(12, xtype=XType.point2d, default=Vector(0, 0)), # View center point (in DCS)
'snap_base_point': DXFAttr(13, xtype=XType.point2d, default=Vector(0, 0)),
'snap_spacing': DXFAttr(14, xtype=XType.point2d, default=Vector(10, 10)),
'grid_spacing': DXFAttr(15, xtype=XType.point2d, default=Vector(10, 10)),
'view_direction_vector': DXFAttr(16, xtype=XType.point3d, default=Vector(0, 0, 0)), # View direction vector (WCS)
'view_target_point': DXFAttr(17, xtype=XType.point3d, default=Vector(0, 0, 0)), # View target point (in WCS)
'perspective_lens_length': DXFAttr(42, default=50),
'front_clip_plane_z_value': DXFAttr(43, default=0),
'back_clip_plane_z_value': DXFAttr(44, default=0),
'view_height': DXFAttr(45, default=1), # View height (in model space units)
'snap_angle': DXFAttr(50, default=0),
'view_twist_angle': DXFAttr(51, default=0),
'circle_zoom': DXFAttr(72, default=100),
# 331: Frozen layer object ID/handle (multiple entries may exist) (optional)
'flags': DXFAttr(90, default=0),
# Viewport status bit-coded flags:
# 1 (0x1) = Enables perspective mode
# 2 (0x2) = Enables front clipping
# 4 (0x4) = Enables back clipping
# 8 (0x8) = Enables UCS follow
# 16 (0x10) = Enables front clip not at eye
# 32 (0x20) = Enables UCS icon visibility
# 64 (0x40) = Enables UCS icon at origin
# 128 (0x80) = Enables fast zoom
# 256 (0x100) = Enables snap mode
# 512 (0x200) = Enables grid mode
'dimtp': DXFAttr(47, default=0),
'dimtm': DXFAttr(48, default=0),
# undocumented: length of extension line if fixed (dimfxlon = 1)
'dimfxl': DXFAttr(49, dxfversion=DXF2007, default=2.5),
# jog angle, Angle of oblique dimension line segment in jogged radius dimension
'dimjogang': DXFAttr(50, dxfversion=DXF2007, default=90, optional=True),
'dimtxt': DXFAttr(140, default=2.5), # measurement text height
'dimcen': DXFAttr(141, default=2.5), # center marks and center lines; 0 = off, <0 = center line, >0 = center mark
'dimtsz': DXFAttr(142, default=0),
'dimaltf': DXFAttr(143, default=0.03937007874),
'dimlfac': DXFAttr(144, default=1), # length factor
'dimtvp': DXFAttr(145, default=0), # text vertical position if dimtad=0
'dimtfac': DXFAttr(146, default=1),
'dimgap': DXFAttr(147, default=.625), # default gap around the measurement text
'dimaltrnd': DXFAttr(148, dxfversion=DXF2000, default=0),
'dimtfill': DXFAttr(69, dxfversion=DXF2007, default=0), # 0=None, 1=canvas color, 2=dimtfillclr
'dimtfillclr': DXFAttr(70, dxfversion=DXF2007, default=0), # color index for dimtfill==2
'dimtol': DXFAttr(71, default=0),
'dimlim': DXFAttr(72, default=0),
'dimtih': DXFAttr(73, default=0), # text inside horizontal
'dimtoh': DXFAttr(74, default=0), # text outside horizontal
'dimse1': DXFAttr(75, default=0), # suppress extension line 1
'dimse2': DXFAttr(76, default=0), # suppress extension line 2
'dimtad': DXFAttr(77, default=1), # 0=center; 1+2+3=above; 4=below
'dimzin': DXFAttr(78, default=8),
'dimazin': DXFAttr(79, default=0, dxfversion=DXF2000),
'unknown1': DXFAttr(90, dxfversion=DXF2000, optional=True),
'dimalt': DXFAttr(170, default=0),
'dimaltd': DXFAttr(171, default=3),
'dimtofl': DXFAttr(172, default=1),
'dimsah': DXFAttr(173, default=0),
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:
tags = processor.load_dxfattribs_into_namespace(dxf, acdb_tolerance)
if len(tags):
tagwriter.write_tags(self.tags)
@register_entity
class MultiLeader(MLeader):
DXFTYPE = 'MULTILEADER'
acdb_mleader_style = DefSubclass('AcDbMLeaderStyle', {
'unknown1': DXFAttr(179, default=2),
'content_type': DXFAttr(170, default=2),
'draw_mleader_order_type': DXFAttr(171, default=1),
'draw_leader_order_type': DXFAttr(172, default=0),
'max_leader_segments_points': DXFAttr(90, default=2), # MaxLeader Segments Points
'first_segment_angle_constraint': DXFAttr(40, default=0.0), # First Segment Angle Constraint
'second_segment_angle_constraint': DXFAttr(41, default=0.0), # Second Segment Angle Constraint
'leader_line_type': DXFAttr(173, default=1),
'leader_line_color': DXFAttr(91, default=-1056964608),
'leader_line_type_handle': DXFAttr(340), # handle
'leader_line_weight': DXFAttr(92, default=-2),
'enable_landing': DXFAttr(290, default=1),
'landing_gap': DXFAttr(42, default=2.0),
'enable_dog_leg': DXFAttr(291, default=1),
'dog_leg_length': DXFAttr(43, default=8),
'name': DXFAttr(3, default='Standard'),
'arrow_head_handle': DXFAttr(341), # no handle is default arrow 'closed filled'
'arrow_head_size': DXFAttr(44, default=4),
'default_mtext_contents': DXFAttr(300, default=''),
'text_style_handle': DXFAttr(342), # handle to text style 'Standard'
'text_left_attachment_type': DXFAttr(174, default=1),
'text_angle_type': DXFAttr(175, default=1),
'text_alignment_type': DXFAttr(176, default=0),
'dimdsep': DXFAttr(278, dxfversion=DXF2000, default=44),
# 0 = Moves the dimension line with dimension text
# 1 = Adds a leader when dimension text is moved
# 2 = Allows text to be moved freely without a leader
'dimtmove': DXFAttr(279, dxfversion=DXF2000, default=0),
'dimjust': DXFAttr(280, dxfversion=DXF2000, default=0), # 0=center; 1=left; 2=right; 3=above ext1; 4=above ext2
'dimsd1': DXFAttr(281, dxfversion=DXF2000, default=0), # suppress first part of the dimension line
'dimsd2': DXFAttr(282, dxfversion=DXF2000, default=0), # suppress second part of the dimension line
'dimtolj': DXFAttr(283, dxfversion=DXF2000, default=0),
'dimtzin': DXFAttr(284, dxfversion=DXF2000, default=8),
'dimaltz': DXFAttr(285, dxfversion=DXF2000, default=0),
'dimalttz': DXFAttr(286, dxfversion=DXF2000, default=0),
'dimfit': DXFAttr(287), # obsolete, now use DIMATFIT and DIMTMOVE
'dimupt': DXFAttr(288, dxfversion=DXF2000, default=0),
# 0 = Places both text and arrows outside extension lines
# 1 = Moves arrows first, then text
# 2 = Moves text first, then arrows
# 3 = Moves either text or arrows, whichever fits best
'dimatfit': DXFAttr(289, dxfversion=DXF2000, default=3),
'dimfxlon': DXFAttr(290, dxfversion=DXF2007, default=0), # undocumented: 1 = fixed extension line length
# virtual DXF attribute 'dimtxsty': set/get STYLE by name
'dimtxsty': DXFAttr(VIRTUAL_TAG, dxfversion=DXF2000),
# virtual DXF attribute 'dimldrblk': set/get leader arrow by block name
'dimldrblk': DXFAttr(VIRTUAL_TAG, dxfversion=DXF2000),
# virtual DXF attribute 'dimltex1': set/get referenced LINETYPE by name as callback
'dimltex1': DXFAttr(VIRTUAL_TAG, dxfversion=DXF2007),
# handles not used internally, handles are set at export
'dimtxsty_handle': DXFAttr(340, dxfversion=DXF2000), # handle of referenced STYLE entry
'dimblk_handle': DXFAttr(342, dxfversion=DXF2000), # handle of referenced BLOCK_RECORD
'dimblk1_handle': DXFAttr(343, dxfversion=DXF2000), # handle of referenced BLOCK_RECORD
'dimblk2_handle': DXFAttr(344, dxfversion=DXF2000), # handle of referenced BLOCK_RECORD
'dimldrblk_handle': DXFAttr(341, dxfversion=DXF2000), # handle of referenced BLOCK_RECORD
'dimltype_handle': DXFAttr(345, dxfversion=DXF2007), # handle of linetype for dimension line
'dimltex1_handle': DXFAttr(346, dxfversion=DXF2007), # handle of linetype for extension line 1
'dimltex2_handle': DXFAttr(347, dxfversion=DXF2007), # handle of linetype for extension line 2
# dimension line lineweight enum value, default BYBLOCK
'dimlwd': DXFAttr(371, default=LINEWEIGHT_BYBLOCK, dxfversion=DXF2000),
# extension line lineweight enum value, default BYBLOCK
'dimlwe': DXFAttr(372, default=LINEWEIGHT_BYBLOCK, dxfversion=DXF2000),
})
EXPORT_MAP_R2007 = [
'name', 'flags', 'dimscale', 'dimasz', 'dimexo', 'dimdli', 'dimexe', 'dimrnd', 'dimdle', 'dimtp', 'dimtm', 'dimfxl',
'dimjogang', 'dimtxt', 'dimcen', 'dimtsz', 'dimaltf', 'dimlfac', 'dimtvp', 'dimtfac', 'dimgap', 'dimaltrnd',
'dimtfill', 'dimtfillclr', 'dimtol', 'dimlim', 'dimtih', 'dimtoh', 'dimse1', 'dimse2', 'dimtad', 'dimzin',
'dimazin', 'unknown1', 'dimalt', 'dimaltd', 'dimtofl', 'dimsah', 'dimtix', 'dimsoxd', 'dimclrd', 'dimclre',
'dimclrt', 'dimadec', 'dimdec', 'dimtdec', 'dimaltu', 'dimalttd', 'dimaunit', 'dimfrac', 'dimlunit', 'dimdsep',
'dimtmove', 'dimjust', 'dimsd1', 'dimsd2', 'dimtolj', 'dimtzin', 'dimaltz', 'dimalttz', 'dimupt', 'dimatfit',
'dimfxlon', 'dimtxsty_handle', 'dimldrblk_handle', 'dimblk_handle', 'dimblk1_handle', 'dimblk2_handle',
'dimltype_handle', 'dimltex1_handle', 'dimltex2_handle', 'dimlwd', 'dimlwe'
]
.. versionadded:: 0.12
"""
return explode_entity(self, target_layout)
acdb_arc_dimension = DefSubclass('AcDbArcDimension', {
'ext_line1_point': DXFAttr(13, xtype=XType.point3d, default=Vector(0, 0, 0)),
'ext_line2_point': DXFAttr(14, xtype=XType.point3d, default=Vector(0, 0, 0)),
'arc_center': DXFAttr(15, xtype=XType.point3d, default=Vector(0, 0, 0)),
'start_angle': DXFAttr(40), # radians?
'end_angle': DXFAttr(41), # radians?
'is_partial': DXFAttr(70),
'has_leader': DXFAttr(71),
'leader_point1': DXFAttr(16, xtype=XType.point3d, default=Vector(0, 0, 0)),
'leader_point2': DXFAttr(17, xtype=XType.point3d, default=Vector(0, 0, 0)),
})
@register_entity
class ArcDimension(Dimension):
""" DXF ARC_DIMENSION entity """
DXFTYPE = 'ARC_DIMENSION'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_dimension, acdb_arc_dimension)
MIN_DXF_VERSION_FOR_EXPORT = DXF2000
def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
# skip Dimension loader
dxf = super(Dimension, self).load_dxf_attribs(processor)
if processor:
tags = processor.load_dxfattribs_into_namespace(dxf, acdb_dimension)