def _setup(self): self.header = HeaderSection.new() self.classes = ClassesSection(self) self.tables = TablesSection(self) self.blocks = BlocksSection(self) self.entities = EntitySection(self) self.objects = ObjectsSection(self) self.acdsdata = AcDsDataSection(self) # AcDSData section is not supported for new drawings self.rootdict = self.objects.rootdict self.objects.setup_objects_management_tables(self.rootdict) # create missing tables self.layouts = Layouts.setup(self) self._finalize_setup()
def test_acdsrecord(self): section = AcDsDataSection(ACDSSECTION, DrawingProxy('AC1027')) records = [entity for entity in section.entities if entity.dxftype() == 'ACDSRECORD'] self.assertTrue(len(records) > 0) record = records[0] self.assertTrue(record.has_section('ASM_Data')) self.assertTrue(record.has_section('AcDbDs::ID')) self.assertFalse(record.has_section('mozman')) with self.assertRaises(KeyError): asm_data = record['mozman'] asm_data = record['ASM_Data'] binary_data = (tag for tag in asm_data if tag.code == 310) length = sum(len(tag.value) for tag in binary_data) / 2 self.assertEqual(asm_data[2].value, length)
def test_build(self): section = AcDsDataSection(ACDSSECTION, DrawingProxy('AC1027')) self.assertEqual('ACDSDATA', section.name.upper()) self.assertTrue(len(section.entities) > 0)
def _load_section_dict(self, sections: loader.SectionDict) -> None: """ Internal API to load a DXF document from a section dict. """ self.is_loading = True # Create header section: # All header tags are the first DXF structure entity header_entities = sections.get('HEADER', [None])[0] if header_entities is None: # Create default header, files without header are by default DXF R12 self.header = HeaderSection.new(dxfversion=DXF12) else: self.header = HeaderSection.load(header_entities) self._dxfversion: str = self.header.get('$ACADVER', DXF12) # Store original DXF version of loaded file. self._loaded_dxfversion = self._dxfversion # Content encoding: self.encoding = toencoding(self.header.get('$DWGCODEPAGE', 'ANSI_1252')) # Set handle seed: seed: str = self.header.get('$HANDSEED', str(self.entitydb.handles)) self.entitydb.handles.reset(_validate_handle_seed(seed)) # Store all necessary DXF entities in the entity database: loader.load_and_bind_dxf_content(sections, self) # End of 1. loading stage, all entities of the DXF file are # stored in the entity database. # Create sections: self.classes = ClassesSection(self, sections.get('CLASSES', None)) self.tables = TablesSection(self, sections.get('TABLES', None)) # Create *Model_Space and *Paper_Space BLOCK_RECORDS # BlockSection setup takes care about the rest: self._create_required_block_records() # At this point all table entries are required: self.blocks = BlocksSection(self, sections.get('BLOCKS', None)) self.entities = EntitySection(self, sections.get('ENTITIES', None)) self.objects = ObjectsSection(self, sections.get('OBJECTS', None)) # only DXF R2013+ self.acdsdata = AcDsDataSection(self, sections.get('ACDSDATA', None)) # Store unmanaged sections as raw tags: for name, data in sections.items(): if name not in const.MANAGED_SECTIONS: self.stored_sections.append(StoredSection(data)) # Objects section is not initialized! self._2nd_loading_stage() # DXF version upgrades: if self.dxfversion < DXF12: logger.info('DXF version upgrade to DXF R12.') self.dxfversion = DXF12 if self.dxfversion == DXF12: self.tables.create_table_handles() if self.dxfversion in (DXF13, DXF14): logger.info('DXF version upgrade to DXF R2000.') self.dxfversion = DXF2000 self.create_all_arrow_blocks() # Objects section setup: self.rootdict = self.objects.rootdict # Create missing management tables (DICTIONARY): self.objects.setup_objects_management_tables(self.rootdict) # Setup modelspace- and paperspace layouts: self.layouts = Layouts.load(self) # Additional work is common to the new and load process: self.is_loading = False self._finalize_setup()
def _load(self, tagger: Iterable['DXFTag']): sections = load_dxf_structure( tagger) # load complete DXF entity structure try: # discard section THUMBNAILIMAGE del sections['THUMBNAILIMAGE'] except KeyError: pass # ----------------------------------------------------------------------------------- # create header section: # all header tags are the first DXF structure entity header_entities = sections.get('HEADER', [None])[0] if header_entities is None: # create default header, files without header are by default DXF R12 self.header = HeaderSection.new(dxfversion=DXF12) else: self.header = HeaderSection.load(header_entities) # ----------------------------------------------------------------------------------- # missing $ACADVER defaults to DXF R12 self._dxfversion = self.header.get('$ACADVER', DXF12) # type: str self._loaded_dxfversion = self._dxfversion # save dxf version of loaded file self.encoding = toencoding(self.header.get( '$DWGCODEPAGE', 'ANSI_1252')) # type: str # read/write # get handle seed seed = self.header.get('$HANDSEED', str(self.entitydb.handles)) # type: str # setup handles self.entitydb.handles.reset(seed) # store all necessary DXF entities in the drawing database fill_database(sections, self.dxffactory) # all handles used in the DXF file are known at this point # ----------------------------------------------------------------------------------- # create sections: self.classes = ClassesSection(self, sections.get('CLASSES', None)) self.tables = TablesSection(self, sections.get('TABLES', None)) # create *Model_Space and *Paper_Space BLOCK_RECORDS # BlockSection setup takes care about the rest self._create_required_block_records() # table records available self.blocks = BlocksSection(self, sections.get('BLOCKS', None)) self.entities = EntitySection(self, sections.get('ENTITIES', None)) self.objects = ObjectsSection(self, sections.get('OBJECTS', None)) # only valid for DXF R2013 and later self.acdsdata = AcDsDataSection(self, sections.get('ACDSDATA', None)) for name, data in sections.items(): if name not in MANAGED_SECTIONS: self.stored_sections.append(StoredSection(data)) # ----------------------------------------------------------------------------------- if self.dxfversion < DXF12: # upgrade to DXF R12 logger.info('Upgrading drawing to DXF R12.') self.dxfversion = DXF12 # DIMSTYLE: ezdxf uses names for blocks, linetypes and text style as internal data, handles are set at export # requires BLOCKS and TABLES section! self.tables.resolve_dimstyle_names() if self.dxfversion == DXF12: # TABLE requires in DXF12 no handle and has no owner tag, but DXF R2000+, requires a TABLE with handle # and each table entry has an owner tag, pointing to the TABLE entry self.tables.create_table_handles() if self.dxfversion in (DXF13, DXF14): # upgrade to DXF R2000 self.dxfversion = DXF2000 self.rootdict = self.objects.rootdict self.objects.setup_objects_management_tables( self.rootdict) # create missing tables self.layouts = Layouts.load(self) self._finalize_setup()
def section(dwg): dxf = load_section(ACDSSECTION, 'ACDSDATA') return AcDsDataSection(dxf, dwg)
def section(): entities = group_tags(internal_tag_compiler(ACDSSECTION)) return AcDsDataSection(None, entities)