def __init__(self, filename): """ Try reading a dxf file pointed by filename and save the floor in the respective attribute. Arguments: - filename: string rapresents the filename with path of the dxf file. Raise: - FileUpdateException in case of impossibility to identify building, floor or rooms. Initialise a DxfReader, try to read a dxf file and associate the texts found to the respective room. Call the FloorInference class to find a standard floor id, and save the results of the operations in the floor attribute as a Floor object. """ self._filename = filename self._basename = os.path.basename(filename) self.floor = None self._read_dxf(self._filename) self._extract_entities() b_id = self._get_b_id(self._basename) if not b_id: raise FileUpdateException( "It was not possible to identify the building associated to the DXF file" ) f_id = FloorInference.get_identifier(self._basename, self._grabber) if not f_id: raise FileUpdateException( "It was not possible to identify the floor associated to the DXF file" ) self.floor = Floor(b_id, f_id, self._rooms, self._wall_lines, self._window_lines) if self.floor.n_rooms == 0: raise FileUpdateException("The floor read has no rooms: " + self._filename) self.floor.associate_room_texts(self._texts) self.floor.normalize() self.floor.discard_tiny_lines()
def __init__(self, filename): """ Try reading a dxf file pointed by filename and save the floor in the respective attribute. Arguments: - filename: string rapresents the filename with path of the dxf file. Raise: - FileUpdateException in case of impossibility to identify building, floor or rooms. Initialise a DxfReader, try to read a dxf file and associate the texts found to the respective room. Call the FloorInference class to find a standard floor id, and save the results of the operations in the floor attribute as a Floor object. """ self._filename = filename; self._basename = os.path.basename(filename) self.floor = None self._read_dxf(self._filename) self._extract_entities() b_id = self._get_b_id(self._basename) if not b_id: raise FileUpdateException("It was not possible to identify the building associated to the DXF file") f_id = FloorInference.get_identifier( self._basename, self._grabber ) if not f_id: raise FileUpdateException("It was not possible to identify the floor associated to the DXF file") self.floor = Floor(b_id, f_id, self._rooms, self._wall_lines, self._window_lines) if self.floor.n_rooms == 0: raise FileUpdateException("The floor read has no rooms: " + self._filename) self.floor.associate_room_texts(self._texts) self.floor.normalize() self.floor.discard_tiny_lines()
from tasks.floor_inference import FloorInference import sys, dxfgrabber, shutil, os if __name__ == "__main__": files = sys.argv[1:] for i in range(len(files)): f = files[i] print(i, " - Processing file", os.path.basename(f)) try: grabber = dxfgrabber.readfile(f, { "resolve_text_styles": False } ) except Exception: print("[ERROR] Eccezione non gestita") n = str(FloorInference.get_identifier(f, grabber)).lower() valid_filename_chars = '-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' directory = "assets/dxf/tutti_con_audit/"+''.join(c for c in n if c in valid_filename_chars)+"/" if( not os.path.exists(directory) ): os.makedirs(directory) shutil.copy(f, directory) sys.stdout.flush() sys.stderr.flush()