How to use the ezdxf.lldxf.attributes.DXFAttributes function in ezdxf

To help you get started, we’ve selected a few ezdxf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozman / ezdxf / ezdxf / modern / spline.py View on Github external
'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

    @property
    def AcDbSpline(self) -> 'Tags':
        return self.tags.subclasses[2]

    @property
    def closed(self) -> bool:
        return self.get_flag_state(self.CLOSED, name='flags')

    @closed.setter
    def closed(self, status: bool) -> None:
github mozman / ezdxf / src / ezdxf / entities / polyline.py View on Github external
# Curve fit tangent direction (in degrees)
    'tangent': DXFAttr(50, optional=True),
    'vtx0': DXFAttr(71, optional=True),
    'vtx1': DXFAttr(72, optional=True),
    'vtx2': DXFAttr(73, optional=True),
    'vtx3': DXFAttr(74, optional=True),
    'vertex_identifier': DXFAttr(91, optional=True),
})


@register_entity
class DXFVertex(DXFGraphic):
    """ DXF VERTEX entity """
    DXFTYPE = 'VERTEX'

    DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_vertex)
    # Extra vertex created by curve-fitting:
    EXTRA_VERTEX_CREATED = 1

    # Curve-fit tangent defined for this vertex. A curve-fit tangent direction
    # of 0 may be omitted from the DXF output, but is significant if this bit
    # is set:
    CURVE_FIT_TANGENT = 2

    # 4 = unused, never set in dxf files
    # Spline vertex created by spline-fitting
    SPLINE_VERTEX_CREATED = 8
    SPLINE_FRAME_CONTROL_POINT = 16
    POLYLINE_3D_VERTEX = 32
    POLYGON_MESH_VERTEX = 64
    POLYFACE_MESH_VERTEX = 128
    FACE_FLAGS = POLYGON_MESH_VERTEX + POLYFACE_MESH_VERTEX
github mozman / ezdxf / ezdxf / modern / graphics.py View on Github external
'thickness': DXFAttr(39, default=0.0),
    'insert': DXFAttr(10, xtype=XType.any_point),
    'size': DXFAttr(40),
    'name': DXFAttr(2),
    'rotation': DXFAttr(50, default=0.0),
    'xscale': DXFAttr(41, default=1.0),
    'oblique': DXFAttr(51, default=0.0),
    'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0.0, 0.0, 1.0)),
})


# SHAPE is not tested with real world DXF drawings!
class Shape(ModernGraphicEntity):
    __slots__ = ()
    TEMPLATE = ExtendedTags.from_text(_SHAPE_TPL)
    DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, shape_subclass)
github mozman / ezdxf / src / ezdxf / entities / dictionary.py View on Github external
)

    def destroy(self) -> None:
        if self.is_hard_owner:
            self._delete_hard_owned_entries()


acdb_dict_with_default = DefSubclass('AcDbDictionaryWithDefault', {
    'default': DXFAttr(340),
})


@register_entity
class DictionaryWithDefault(Dictionary):
    DXFTYPE = 'ACDBDICTIONARYWDFLT'
    DXFATTRIBS = DXFAttributes(base_class, acdb_dictionary, acdb_dict_with_default)

    def __init__(self, doc: 'Drawing' = None):
        super().__init__(doc)
        self._default = None  # type: DXFEntity

    def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
        dxf = super().load_dxf_attribs(processor)
        if processor is None:
            return dxf

        processor.load_dxfattribs_into_namespace(dxf, acdb_dict_with_default)
        return dxf

    def export_entity(self, tagwriter: 'TagWriter') -> None:
        super().export_entity(tagwriter)
        tagwriter.write_tag2(SUBCLASS_MARKER, acdb_dict_with_default.name)
github mozman / ezdxf / src / ezdxf / entities / dimension.py View on Github external
return {}
        attribs = {}
        codes = dim_style.CODE_TO_DXF_ATTRIB
        for code_tag, value_tag in take2(data):
            group_code = code_tag.value
            value = value_tag.value
            if group_code in codes:
                attribs[codes[group_code]] = value
        return self.dim_style_attr_handles_to_names(attribs)


@register_entity
class Dimension(DXFGraphic, OverrideMixin):
    """ DXF DIMENSION entity """
    DXFTYPE = 'DIMENSION'
    DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_dimension, acdb_dimension_dummy)
    LINEAR = 0
    ALIGNED = 1
    ANGULAR = 2
    DIAMETER = 3
    RADIUS = 4
    ANGULAR_3P = 5
    ORDINATE = 6
    ARC = 8
    ORDINATE_TYPE = 64
    USER_LOCATION_OVERRIDE = 128

    # WARNING for destroy() method:
    # Do not destroy associated anonymous block, if DIMENSION is used in a block, the anonymous block may
    # be used by several block references.

    def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
github mozman / ezdxf / src / ezdxf / entities / attrib.py View on Github external
'field_length': DXFAttr(73, default=0, optional=True),  # Field length (optional) (not currently used)
    # Vertical text justification type (optional); see group code 73 in TEXT
    'valign': DXFAttr(74, default=0, optional=True),
    # Lock position flag. Locks the position of the attribute within the block reference
    # example of double use of group codes in one sub class
    'lock_position': DXFAttr(280, default=0, dxfversion=DXF2010, optional=True),
})


@register_entity
class Attrib(BaseAttrib):
    """ DXF ATTRIB entity """

    DXFTYPE = 'ATTRIB'
    DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_text, acdb_attrib)  # don't add acdb_attdef_xrecord here

    def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
        dxf = super(Text, self).load_dxf_attribs(processor)
        # do not call Text loader
        if processor:
            tags = processor.load_dxfattribs_into_namespace(dxf, acdb_text)
            if len(tags) and not processor.r12:
                processor.log_unprocessed_tags(tags, subclass=acdb_text.name)

            tags = processor.load_dxfattribs_into_namespace(dxf, acdb_attrib)
            if len(tags) and not processor.r12:
                processor.log_unprocessed_tags(tags, subclass=acdb_attrib.name)
            self.xrecord = processor.find_subclass(self.XRECORD_DEF.name)
        return dxf

    def export_entity(self, tagwriter: 'TagWriter') -> None:
github mozman / ezdxf / experiments / new_entity_system.py View on Github external
# 3 = Ignores shadows
})


class DXFAttribs:  # different for every DXF type
    """
    Uses the Python object itself as attribute storage, only valid Python names can be used as attrib name.

    Ignore invalid dxf attributes at first for simplicity, DXF validation can be added later.
    Invalid attributes will not be written by the export function.

    """
    # how to implement DXF R12 and DXF R2000+ support by just one DXF attribute definition?
    # for DXF R12 has no subclasses -> use DXF R2000+ definition and just ignore subclasses?

    DXFATTRIBS = DXFAttributes(main_class, entity_subclass)

    def __init__(self, subclasses: List[Tags], doc):
        assert len(subclasses)
        mainclass = subclasses[0]

        # bypass __setattr__() because without DXF attributes definition
        self.__dict__['dxfversion'] = doc.dxfversion
        self.__dict__['dxftype'] = mainclass[0].value  # value of first tag is always the dxftype e.g. (0, LINE)
        code = handle_code(self.dxftype)
        self.handle = mainclass.get_first_value(code, None)  # CLASS entity has no handle
        if self.dxfversion > 'AC1009':
            self.owner = mainclass.get_first_value(330, None)  # owner

    def __getattr__(self, key: str):
        """ called if key does not exist """
        if self.is_supported(key):
github mozman / ezdxf / src / ezdxf / entities / dxfobj.py View on Github external
})


def totags(tags: Iterable) -> Iterable[DXFTag]:
    for tag in tags:
        if isinstance(tag, DXFTag):
            yield tag
        else:
            yield dxftag(tag[0], tag[1])


@register_entity
class XRecord(DXFObject):
    """ DXF XRECORD entity """
    DXFTYPE = 'XRECORD'
    DXFATTRIBS = DXFAttributes(base_class, acdb_xrecord)

    def __init__(self, doc: 'Drawing' = None):
        super().__init__(doc)
        self.tags = Tags()

    def _copy_data(self, entity: 'XRecord') -> None:
        entity.tags = Tags(entity.tags)

    def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
        dxf = super().load_dxf_attribs(processor)
        if processor:
            try:
                tags = processor.subclasses[1]
            except IndexError:
                raise DXFStructureError('Missing subclass AcDbXrecord in XRecord (#{})'.format(dxf.handle))
            start_index = 1
github mozman / ezdxf / src / ezdxf / entities / text.py View on Github external
})

acdb_text2 = DefSubclass('AcDbText', {
    'valign': DXFAttr(73, default=0, optional=True)  # Vertical text justification type (optional)
    # 0 = Baseline
    # 1 = Bottom
    # 2 = Middle
    # 3 = Top
})


@register_entity
class Text(DXFGraphic):
    """ DXF TEXT entity """
    DXFTYPE = 'TEXT'
    DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_text, acdb_text2)
    # horizontal align values
    LEFT = 0
    CENTER = 1
    RIGHT = 2
    # vertical align values
    BASELINE = 0
    BOTTOM = 1
    MIDDLE = 2
    TOP = 3
    # text generation flags
    MIRROR_X = 2
    MIRROR_Y = 4
    BACKWARD = MIRROR_X
    UPSIDE_DOWN = MIRROR_Y

    def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
github mozman / ezdxf / ezdxf / modern / tableentries.py View on Github external
AcDbRegAppTableRecord
2
APPIDNAME
70
0
"""
appid_subclass = DefSubclass('AcDbRegAppTableRecord', {
    'name': DXFAttr(2),
    'flags': DXFAttr(70),
})


class AppID(legacy.AppID):
    __slots__ = ()
    TEMPLATE = ExtendedTags.from_text(_APPIDTEMPLATE)
    DXFATTRIBS = DXFAttributes(none_subclass, symbol_subclass, appid_subclass)


_DIMSTYLETEMPLATE = """0
DIMSTYLE
105
0
100
AcDbSymbolTableRecord
100
AcDbDimStyleTableRecord
2
STANDARD
70
0
3