def test_xrecord_with_long_closing_tag(): tags = ExtendedTags(Tags.from_text(XRECORD_APP_DATA_LONG_CLOSING_TAG)) assert tags.dxftype() == "XRECORD" # real app data just exists only in the base class, app data marker in AcDbXrecord are just tags, interpreted by # the associated application assert len(tags.appdata) == 1 assert len(tags.subclasses[1]) == 35
def add_tags(self, tags: ExtendedTags) -> str: try: handle = tags.get_handle() except DXFValueError: # create new handle handle = self.get_unique_handle() handle_code = 105 if tags.dxftype() == 'DIMSTYLE' else 5 # legacy shit!!! tags.noclass.insert(1, DXFTag(handle_code, handle)) # handle should be the 2. tag self.__setitem__(handle, tags) return handle
def test_xrecord_with_group_code_102(): tags = ExtendedTags(Tags.from_text(XRECORD_WITH_GROUP_CODE_102)) assert tags.dxftype() == 'XRECORD' assert len(tags.appdata) == 1 assert tags.noclass[2] == (102, 0) # 0 == index in appdata list assert tags.appdata[0][0] == (102, '{ACAD_REACTORS') xrecord = tags.get_subclass('AcDbXrecord') assert xrecord[2] == (102, 'ACAD_ROUNDTRIP_PRE2007_TABLESTYLE') assert len(list(tags)) * 2 + 1 == len(XRECORD_WITH_GROUP_CODE_102.split('\n')) # +1 == appending '\n'
def __init__(self, tags: ExtendedTags, dxfversion=None): if len(tags.subclasses) == 0: raise ValueError('Invalid tags.') self.subclasses = list(tags.subclasses) # type: List[Tags] # copy subclasses self.dxfversion = dxfversion # DXF R12 and prior have no subclass marker system, all tags of an entity in one flat list # Where later DXF versions have at least 2 subclasses base_class and AcDbEntity # Exception CLASS has also only one subclass and no subclass marker, handled as DXF R12 entity self.r12 = (dxfversion == DXF12) or (len(self.subclasses) == 1) self.name = tags.dxftype() try: self.handle = tags.get_handle() except DXFValueError: self.handle = '<?>'
def modelspace(self) -> Iterable[DXFGraphic]: """ Returns an iterator for all supported DXF entities in the modelspace. These entities are regular :class:`~ezdxf.entities.DXFGraphic` objects but without a valid document assigned. It is **not** possible to add these entities to other `ezdxf` documents. It is only possible to recreate the objects by factory functions base on attributes of the source entity. For MESH, POLYMESH and POLYFACE it is possible to use the :class:`~ezdxf.render.MeshTransformer` class to render (recreate) this objects as new entities in another document. """ if self._fp_entities_section is None: self._fp_entities_section = self._seek_to_section('ENTITIES') self.file.seek(self._fp_entities_section) tags = [] factory = EntityFactory() polyline: Optional[Polyline] = None for tag in tag_compiler(low_level_tagger(self.file)): if tag.code == 0: # start new entity if len(tags): xtags = ExtendedTags(tags) dxftype = xtags.dxftype() if dxftype in SUPPORTED_DXF_TYPES: entity = factory.entity(xtags) if dxftype == 'SEQEND': if polyline is not None: polyline.seqend = entity yield polyline polyline = None # suppress all other SEQEND entities -> ATTRIB elif dxftype == 'VERTEX' and polyline is not None: # vertices without POLYLINE are DXF structure errors, but here just ignore it. polyline.vertices.append(entity) elif dxftype == 'POLYLINE': polyline = entity else: # POLYLINE without SEQEND is a DXF structure error, but here just ignore it. # By using this add-on be sure to get valid DXF files. polyline = None yield entity if tag == (0, 'ENDSEC'): break tags = [tag] else: tags.append(tag)
def test_group_code_1000_outside_XDATA(): tags = ExtendedTags(Tags.from_text(BLOCKBASEPOINTPARAMETER_CVIL_3D_2018)) assert tags.dxftype() == 'BLOCKBASEPOINTPARAMETER' assert len(tags.subclasses) == 6 block_base_point_parameter = tags.get_subclass('AcDbBlockBasepointParameter') assert len(block_base_point_parameter) == 3 assert block_base_point_parameter[0] == (100, 'AcDbBlockBasepointParameter') assert block_base_point_parameter[1] == (1011, (0., 0., 0.)) assert block_base_point_parameter[2] == (1012, (0., 0., 0.)) block_element = tags.get_subclass('AcDbBlockElement') assert block_element[4] == (1071, 0) stream = StringIO() tagwriter = TagWriter(stream) tagwriter.write_tags(tags) lines = stream.getvalue() stream.close() assert len(lines.split('\n')) == len(BLOCKBASEPOINTPARAMETER_CVIL_3D_2018.split('\n'))
def test_xrecord_with_long_closing_tag(): tags = ExtendedTags(Tags.from_text(XRECORD_APP_DATA_LONG_CLOSING_TAG)) assert tags.dxftype() == 'XRECORD' assert len(tags.appdata) == 5 attr_rec = tags.appdata[4] assert attr_rec[0] == (102, '{ATTRRECORD') assert attr_rec[1] == (341, '2FD') assert len(list(tags)) * 2 + 1 == len( XRECORD_APP_DATA_LONG_CLOSING_TAG.split('\n')) # +1 == appending '\n' # test USUAL_102_TAG_INSIDE_APP_DATA attr_rec = tags.appdata[1] assert attr_rec[0] == (102, '{ATTRRECORD') assert attr_rec[1] == (341, '2FA') assert attr_rec[2] == (102, 'USUAL_102_TAG_INSIDE_APP_DATA') # test USUAL_102_TAG_OUTSIDE_APP_DATA xrecord = tags.get_subclass('AcDbXrecord') assert xrecord[4] == (102, 'USUAL_102_TAG_OUTSIDE_APP_DATA')