def main(): acad = Autocad() print u'Примерный подсчет занимаемого места' print '%-20s| %s' % (u'Имя щита', u'Общее число модулей') for layout in acad.iter_layouts(): table = acad.find_one('table', layout.Block, lambda x: x.Columns == 5) if not table: continue total_modules = 0 row = -1 while row < table.Rows: row += 1 item_str = mtext_to_string(table.GetText(row, 2)) item_str = item_str.replace(u'четырехполюсный', u'4-х')\ .replace(u'трехполюсный', u'3-х')\ .replace(u'двухполюсный', u'2-х')\ .replace(u'однополюсный', u'1-но') m = re.match(ur'.*(\d)-([xх]|но).*', item_str) if m: n_modules = int(m.group(1)) quantity = int(mtext_to_string(table.GetText(row, 3))) row += 1 # skip next row else: m = re.match(ur'(\d)[PР].*', item_str) if not m: continue n_modules = int(m.group(1)) quantity = int(mtext_to_string(table.GetText(row - 1, 3))) total_modules += n_modules * quantity print '%-20s| %s' % (layout.Name, total_modules)
def iter_cable_tables(acad, block): for table in acad.iter_objects("table", block): if table.Columns != 9: continue ncols = table.Columns # store in local, Automation is expensive for row in xrange(3, table.Rows): yield [utils.mtext_to_string(table.GetText(row, col)) for col in xrange(ncols)]
def iter_cable_tables(acad, block): for table in acad.iter_objects("table", block): if table.Columns != 9: continue ncols = table.Columns # store in local, Automation is expensive for row in xrange(3, table.Rows): yield [ utils.mtext_to_string(table.GetText(row, col)) for col in xrange(ncols) ]