test-extract-tables-with-columns.jsonโข2.85 kB
{"method":"tools/call","params":{"name":"project_execute","arguments":{"projectId":"S000009result_1278407893","code":"# Cerca le colonne/attributi per ogni tabella nel 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 i listLayoutItem (ogni item corrisponde a una tabella)\n tables_with_columns = []\n \n for list_item in root.iter('listLayoutItem'):\n table_info = {}\n \n # Trova listLayoutCommonEntries dentro questo item\n common = list_item.find('.//listLayoutCommonEntries')\n if common is not None:\n table_info['title'] = common.get('listTitle', 'N/A')\n table_info['identifier'] = common.get('layoutIdentifier', 'N/A')\n \n # Trova listGraphicParameterLayoutItems per il netObjectType\n graphic_params = list_item.find('.//listGraphicParameterLayoutItems')\n if graphic_params is not None:\n table_info['net_object_type'] = graphic_params.get('netObjectType', 'N/A')\n \n # Cerca le colonne - potrebbero essere in listLayoutEntries o listLayoutSpecialEntries\n columns = []\n \n # Cerca listLayoutEntries (colonne base)\n for entry in list_item.iter('listLayoutEntry'):\n col_info = {}\n # L'attributeID รจ quello che ci interessa\n attr_id = entry.get('attributeID')\n if attr_id:\n col_info['attribute_id'] = attr_id\n col_info['visible'] = entry.get('visible', 'true')\n col_info['width'] = entry.get('width', 'N/A')\n columns.append(col_info)\n \n # Cerca anche listLayoutSpecialEntry (colonne speciali)\n for entry in list_item.iter('listLayoutSpecialEntry'):\n col_info = {}\n attr_id = entry.get('attributeID')\n if attr_id:\n col_info['attribute_id'] = attr_id\n col_info['type'] = 'special'\n col_info['visible'] = entry.get('visible', 'true')\n columns.append(col_info)\n \n if table_info:\n table_info['columns'] = columns\n table_info['total_columns'] = len(columns)\n tables_with_columns.append(table_info)\n \n result['total_tables'] = len(tables_with_columns)\n result['tables'] = tables_with_columns\n \nexcept Exception as e:\n result['error'] = str(e)\n import traceback\n result['traceback'] = traceback.format_exc()[:500]\nresult","description":"Estrai tabelle con tutte le colonne/attributi"}},"jsonrpc":"2.0","id":23}