def get_cables(acad, block, known_targets): patterns = [ur"""(?P<cable>.*?)-(?P<section>[\dxх,\(\)]+)\s+ (?P<length>\d+)\s*[мm]\\P \s*(?P<name>[^-]+)-(?P<source>.+)\s*""", ur"""(?P<name>.*?)-(?P<source>.*?)\s*\\P \s*(?P<cable>.*?)-(?P<section>[\dxх,\(\)]+)\s+ (?P<length>\d+)\s*[мm]"""] patterns = [re.compile(pat, re.VERBOSE) for pat in patterns] for text in acad.iter_objects("dbmtext", block): text = unformat_mtext(text.TextString) logger.info(text) m_cable = None for pattern in patterns: m_cable = pattern.match(text) if m_cable: break if not m_cable: continue logger.info("!!!%s\n", text) m = m_cable.groupdict() cable_name = "%s-%s" % (m['name'], m['source']) target = known_targets.get(cable_name, '') if not target: target = m['name'] yield CableEntry(cable_name, m['source'], target, m['cable'], m['section'], m['length'])
def iter_lamps(acad, objects): for obj in acad.iter_objects(('MText', 'MLeader'), block=objects): try: text = obj.TextString except Exception: continue text = utils.unformat_mtext(text) m = re.search(ur'(?P<num>\d+)(?P<mark>.*?)\\S(?P<num_power>.*?)/.*?;', text) if not m: continue print m.group('num'), m.group('mark'), m.group('num_power') yield LampEntry(m.group('num'), m.group('mark'), m.group('num_power'))