test-extract-all-tables.jsonā¢2.62 kB
{"method":"tools/call","params":{"name":"project_execute","arguments":{"projectId":"S000009result_1278407893","code":"# Estrai tutte le tabelle visibili con le loro colonne dal layout XML\nimport os\nimport xml.etree.ElementTree as ET\nresult = {}\ntry:\n project_path = visum.GetPath(1)\n project_dir = os.path.dirname(project_path)\n lay_file = os.path.join(project_dir, 'tabelle_report.lay')\n \n tree = ET.parse(lay_file)\n root = tree.getroot()\n \n # Trova tutti gli elementi listLayoutCommonEntries\n tables_list = []\n \n for list_common in root.iter('listLayoutCommonEntries'):\n table_info = {\n 'title': list_common.get('listTitle', 'N/A'),\n 'identifier': list_common.get('layoutIdentifier', 'N/A'),\n 'columns': []\n }\n \n # Cerca il netObjectType dal padre o dai figli\n # Cerca listGraphicParameterLayoutItems che ha netObjectType\n parent = list_common.find('..')\n if parent is not None:\n for sibling in parent:\n if sibling.tag == 'listGraphicParameterLayoutItems':\n table_info['net_object_type'] = sibling.get('netObjectType', 'N/A')\n break\n \n # Cerca le colonne (attributi visualizzati)\n # Cerca elementi con 'attribute' o 'column' nel nome\n for elem in parent.iter() if parent else []:\n if 'attribute' in elem.tag.lower():\n # Potrebbe contenere l'ID dell'attributo\n attr_id = elem.get('id') or elem.get('attributeID') or elem.text\n if attr_id:\n table_info['columns'].append(attr_id)\n \n if table_info['title'] != 'N/A':\n tables_list.append(table_info)\n \n result['total_tables'] = len(tables_list)\n result['tables'] = tables_list[:10] # Prime 10 tabelle\n \n # Estrai anche tutte le tabelle con un approccio diverso\n # Cerca elementi che hanno 'listTitle'\n all_list_titles = []\n for elem in root.iter():\n if 'listTitle' in elem.attrib:\n all_list_titles.append({\n 'title': elem.get('listTitle'),\n 'tag': elem.tag,\n 'identifier': elem.get('layoutIdentifier', 'N/A')\n })\n \n result['all_list_titles'] = all_list_titles[:15] # Prime 15\n \nexcept Exception as e:\n result['error'] = str(e)\n import traceback\n result['traceback'] = traceback.format_exc()\nresult","description":"Estrai tutte le tabelle visibili con colonne"}},"jsonrpc":"2.0","id":22}