{
  "schemaVersion": "1.0",
  "item": {
    "slug": "dwg-to-excel",
    "name": "Dwg To Excel",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/datadrivenconstruction/dwg-to-excel",
    "canonicalUrl": "https://clawhub.ai/datadrivenconstruction/dwg-to-excel",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/dwg-to-excel",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=dwg-to-excel",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "claw.json",
      "instructions.md",
      "SKILL.md"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-04-30T16:55:25.780Z",
      "expiresAt": "2026-05-07T16:55:25.780Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=network",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=network",
        "contentDisposition": "attachment; filename=\"network-1.0.0.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/dwg-to-excel"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/dwg-to-excel",
    "agentPageUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent",
    "manifestUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "Problem Statement",
        "body": "AutoCAD DWG files contain valuable project data locked in proprietary format:\n\nLayer structures with drawing organization\nBlock references with attribute data\nText annotations and dimensions\nGeometric entities (lines, polylines, arcs)\nExternal references (xrefs)\n\nExtracting this data typically requires AutoCAD licenses or complex programming."
      },
      {
        "title": "Solution",
        "body": "DwgExporter.exe converts DWG files to structured Excel databases offline, without Autodesk licenses."
      },
      {
        "title": "Business Value",
        "body": "Zero license cost - No AutoCAD license required\nLegacy support - Reads DWG files from 1983 to 2026\nData extraction - Layers, blocks, attributes, text, geometry\nPDF export - Generate drawings from DWG layouts\nBatch processing - Convert thousands of DWG files"
      },
      {
        "title": "CLI Syntax",
        "body": "DwgExporter.exe <input_dwg> [options]"
      },
      {
        "title": "Output Formats",
        "body": "OutputDescription.xlsxExcel database with all entities.pdfPDF drawings from layouts"
      },
      {
        "title": "Supported Versions",
        "body": "Version RangeDescriptionR12 (1992)Legacy DWGR14 (1997)AutoCAD 142000-2002DWG 2000 format2004-2006DWG 2004 format2007-2009DWG 2007 format2010-2012DWG 2010 format2013-2017DWG 2013 format2018-2026DWG 2018 format"
      },
      {
        "title": "Examples",
        "body": "# Basic conversion\nDwgExporter.exe \"C:\\Projects\\FloorPlan.dwg\"\n\n# Export with PDF drawings\nDwgExporter.exe \"C:\\Projects\\FloorPlan.dwg\" sheets2pdf\n\n# Batch processing all DWG in folder\nfor /R \"C:\\Projects\" %f in (*.dwg) do DwgExporter.exe \"%f\"\n\n# PowerShell batch conversion\nGet-ChildItem \"C:\\Projects\\*.dwg\" -Recurse | ForEach-Object {\n    & \"C:\\DDC\\DwgExporter.exe\" $_.FullName\n}"
      },
      {
        "title": "Python Integration",
        "body": "import subprocess\nimport pandas as pd\nfrom pathlib import Path\nfrom typing import List, Optional, Dict, Any\nfrom dataclasses import dataclass\nfrom enum import Enum\n\n\nclass DWGEntityType(Enum):\n    \"\"\"DWG entity types.\"\"\"\n    LINE = \"LINE\"\n    POLYLINE = \"POLYLINE\"\n    LWPOLYLINE = \"LWPOLYLINE\"\n    CIRCLE = \"CIRCLE\"\n    ARC = \"ARC\"\n    ELLIPSE = \"ELLIPSE\"\n    SPLINE = \"SPLINE\"\n    TEXT = \"TEXT\"\n    MTEXT = \"MTEXT\"\n    DIMENSION = \"DIMENSION\"\n    INSERT = \"INSERT\"  # Block reference\n    HATCH = \"HATCH\"\n    SOLID = \"SOLID\"\n    POINT = \"POINT\"\n    ATTRIB = \"ATTRIB\"\n    ATTDEF = \"ATTDEF\"\n\n\n@dataclass\nclass DWGEntity:\n    \"\"\"Represents a DWG entity.\"\"\"\n    handle: str\n    entity_type: str\n    layer: str\n    color: int\n    linetype: str\n    lineweight: float\n\n    # Geometry (depends on entity type)\n    start_x: Optional[float] = None\n    start_y: Optional[float] = None\n    end_x: Optional[float] = None\n    end_y: Optional[float] = None\n\n    # Block reference data\n    block_name: Optional[str] = None\n    rotation: Optional[float] = None\n    scale_x: Optional[float] = None\n    scale_y: Optional[float] = None\n\n    # Text data\n    text_content: Optional[str] = None\n    text_height: Optional[float] = None\n\n\n@dataclass\nclass DWGBlock:\n    \"\"\"Represents a DWG block definition.\"\"\"\n    name: str\n    base_point_x: float\n    base_point_y: float\n    entity_count: int\n    is_dynamic: bool\n    attributes: List[str]\n\n\n@dataclass\nclass DWGLayer:\n    \"\"\"Represents a DWG layer.\"\"\"\n    name: str\n    color: int\n    linetype: str\n    is_on: bool\n    is_frozen: bool\n    is_locked: bool\n    lineweight: float\n    entity_count: int\n\n\nclass DWGExporter:\n    \"\"\"DWG to Excel converter using DDC DwgExporter CLI.\"\"\"\n\n    def __init__(self, exporter_path: str = \"DwgExporter.exe\"):\n        self.exporter = Path(exporter_path)\n        if not self.exporter.exists():\n            raise FileNotFoundError(f\"DwgExporter not found: {exporter_path}\")\n\n    def convert(self, dwg_file: str,\n                export_pdf: bool = False) -> Path:\n        \"\"\"Convert DWG file to Excel.\"\"\"\n        dwg_path = Path(dwg_file)\n        if not dwg_path.exists():\n            raise FileNotFoundError(f\"DWG file not found: {dwg_file}\")\n\n        cmd = [str(self.exporter), str(dwg_path)]\n        if export_pdf:\n            cmd.append(\"sheets2pdf\")\n\n        result = subprocess.run(cmd, capture_output=True, text=True)\n\n        if result.returncode != 0:\n            raise RuntimeError(f\"Export failed: {result.stderr}\")\n\n        # Output file is same name with .xlsx extension\n        return dwg_path.with_suffix('.xlsx')\n\n    def batch_convert(self, folder: str,\n                      include_subfolders: bool = True,\n                      export_pdf: bool = False) -> List[Dict[str, Any]]:\n        \"\"\"Convert all DWG files in folder.\"\"\"\n        folder_path = Path(folder)\n        pattern = \"**/*.dwg\" if include_subfolders else \"*.dwg\"\n\n        results = []\n        for dwg_file in folder_path.glob(pattern):\n            try:\n                output = self.convert(str(dwg_file), export_pdf)\n                results.append({\n                    'input': str(dwg_file),\n                    'output': str(output),\n                    'status': 'success'\n                })\n                print(f\"✓ Converted: {dwg_file.name}\")\n            except Exception as e:\n                results.append({\n                    'input': str(dwg_file),\n                    'output': None,\n                    'status': 'failed',\n                    'error': str(e)\n                })\n                print(f\"✗ Failed: {dwg_file.name} - {e}\")\n\n        return results\n\n    def read_entities(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Read converted Excel as DataFrame.\"\"\"\n        xlsx_path = Path(xlsx_file)\n        if not xlsx_path.exists():\n            raise FileNotFoundError(f\"Excel file not found: {xlsx_file}\")\n\n        return pd.read_excel(xlsx_file, sheet_name=\"Elements\")\n\n    def get_layers(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Get layer summary from converted file.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        if 'Layer' not in df.columns:\n            raise ValueError(\"Layer column not found in data\")\n\n        summary = df.groupby('Layer').agg({\n            'Handle': 'count'\n        }).reset_index()\n        summary.columns = ['Layer', 'Entity_Count']\n        return summary.sort_values('Entity_Count', ascending=False)\n\n    def get_blocks(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Get block reference summary.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Filter to INSERT entities (block references)\n        blocks = df[df['EntityType'] == 'INSERT']\n\n        if blocks.empty:\n            return pd.DataFrame(columns=['Block_Name', 'Count'])\n\n        summary = blocks.groupby('BlockName').agg({\n            'Handle': 'count'\n        }).reset_index()\n        summary.columns = ['Block_Name', 'Count']\n        return summary.sort_values('Count', ascending=False)\n\n    def get_text_content(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Extract all text content from DWG.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Filter to text entities\n        text_types = ['TEXT', 'MTEXT', 'ATTRIB']\n        texts = df[df['EntityType'].isin(text_types)]\n\n        if 'TextContent' in texts.columns:\n            return texts[['Handle', 'EntityType', 'Layer', 'TextContent']].copy()\n        return texts[['Handle', 'EntityType', 'Layer']].copy()\n\n    def get_entity_statistics(self, xlsx_file: str) -> Dict[str, int]:\n        \"\"\"Get entity type statistics.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        if 'EntityType' not in df.columns:\n            return {}\n\n        return df['EntityType'].value_counts().to_dict()\n\n    def extract_block_attributes(self, xlsx_file: str,\n                                  block_name: str) -> pd.DataFrame:\n        \"\"\"Extract attributes from specific block type.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Find block references\n        blocks = df[(df['EntityType'] == 'INSERT') &\n                    (df['BlockName'] == block_name)]\n\n        # Find associated attributes\n        # Attributes typically follow their parent INSERT in handle order\n        result_data = []\n\n        for _, block in blocks.iterrows():\n            block_handle = block['Handle']\n            block_data = {\n                'Block_Handle': block_handle,\n                'X': block.get('InsertX', 0),\n                'Y': block.get('InsertY', 0),\n                'Rotation': block.get('Rotation', 0)\n            }\n\n            # Add any attribute columns\n            for col in df.columns:\n                if col.startswith('Attr_'):\n                    block_data[col] = block.get(col)\n\n            result_data.append(block_data)\n\n        return pd.DataFrame(result_data)\n\n\nclass DWGAnalyzer:\n    \"\"\"Advanced DWG analysis tools.\"\"\"\n\n    def __init__(self, exporter: DWGExporter):\n        self.exporter = exporter\n\n    def analyze_drawing_structure(self, dwg_file: str) -> Dict[str, Any]:\n        \"\"\"Analyze complete drawing structure.\"\"\"\n        xlsx = self.exporter.convert(dwg_file)\n        df = self.exporter.read_entities(str(xlsx))\n\n        analysis = {\n            'file': dwg_file,\n            'total_entities': len(df),\n            'layers': self.exporter.get_layers(str(xlsx)).to_dict('records'),\n            'entity_types': self.exporter.get_entity_statistics(str(xlsx)),\n            'blocks': self.exporter.get_blocks(str(xlsx)).to_dict('records')\n        }\n\n        # Calculate extents if coordinates available\n        if 'X' in df.columns and 'Y' in df.columns:\n            analysis['extents'] = {\n                'min_x': df['X'].min(),\n                'max_x': df['X'].max(),\n                'min_y': df['Y'].min(),\n                'max_y': df['Y'].max()\n            }\n\n        return analysis\n\n    def compare_drawings(self, dwg1: str, dwg2: str) -> Dict[str, Any]:\n        \"\"\"Compare two DWG files.\"\"\"\n        xlsx1 = self.exporter.convert(dwg1)\n        xlsx2 = self.exporter.convert(dwg2)\n\n        df1 = self.exporter.read_entities(str(xlsx1))\n        df2 = self.exporter.read_entities(str(xlsx2))\n\n        layers1 = set(df1['Layer'].unique()) if 'Layer' in df1.columns else set()\n        layers2 = set(df2['Layer'].unique()) if 'Layer' in df2.columns else set()\n\n        return {\n            'file1': dwg1,\n            'file2': dwg2,\n            'entity_count_diff': len(df2) - len(df1),\n            'layers_added': list(layers2 - layers1),\n            'layers_removed': list(layers1 - layers2),\n            'common_layers': list(layers1 & layers2)\n        }\n\n    def find_duplicates(self, xlsx_file: str,\n                        tolerance: float = 0.001) -> pd.DataFrame:\n        \"\"\"Find duplicate entities at same location.\"\"\"\n        df = self.exporter.read_entities(xlsx_file)\n\n        if 'X' not in df.columns or 'Y' not in df.columns:\n            return pd.DataFrame()\n\n        # Round coordinates for grouping\n        df['X_rounded'] = (df['X'] / tolerance).round() * tolerance\n        df['Y_rounded'] = (df['Y'] / tolerance).round() * tolerance\n\n        # Find duplicates\n        duplicates = df[df.duplicated(\n            subset=['EntityType', 'Layer', 'X_rounded', 'Y_rounded'],\n            keep=False\n        )]\n\n        return duplicates.sort_values(['X_rounded', 'Y_rounded'])\n\n\n# Convenience functions\ndef convert_dwg_to_excel(dwg_file: str,\n                         exporter_path: str = \"DwgExporter.exe\") -> str:\n    \"\"\"Quick conversion of DWG to Excel.\"\"\"\n    exporter = DWGExporter(exporter_path)\n    output = exporter.convert(dwg_file)\n    return str(output)\n\n\ndef batch_convert_dwg(folder: str,\n                      exporter_path: str = \"DwgExporter.exe\",\n                      include_subfolders: bool = True) -> List[str]:\n    \"\"\"Batch convert all DWG files in folder.\"\"\"\n    exporter = DWGExporter(exporter_path)\n    results = exporter.batch_convert(folder, include_subfolders)\n    return [r['output'] for r in results if r['status'] == 'success']"
      },
      {
        "title": "Excel Sheets",
        "body": "SheetContentElementsAll DWG entities with propertiesLayersLayer definitionsBlocksBlock definitionsLayoutsDrawing layouts/sheets"
      },
      {
        "title": "Entity Columns",
        "body": "ColumnTypeDescriptionHandlestringUnique entity handleEntityTypestringLINE, CIRCLE, INSERT, etc.LayerstringLayer nameColorintColor index (0-256)LinetypestringLinetype nameLineweightfloatLine weight in mmX, Y, ZfloatEntity coordinatesBlockNamestringFor INSERT entitiesTextContentstringFor TEXT/MTEXT"
      },
      {
        "title": "Quick Start",
        "body": "# Initialize exporter\nexporter = DWGExporter(\"C:/DDC/DwgExporter.exe\")\n\n# Convert single file\nxlsx = exporter.convert(\"C:/Projects/Plan.dwg\")\nprint(f\"Output: {xlsx}\")\n\n# Read and analyze\ndf = exporter.read_entities(str(xlsx))\nprint(f\"Total entities: {len(df)}\")\n\n# Get layer statistics\nlayers = exporter.get_layers(str(xlsx))\nprint(layers)\n\n# Get block usage\nblocks = exporter.get_blocks(str(xlsx))\nprint(blocks)\n\n# Extract text annotations\ntexts = exporter.get_text_content(str(xlsx))\nfor _, row in texts.iterrows():\n    print(f\"{row['Layer']}: {row.get('TextContent', 'N/A')}\")"
      },
      {
        "title": "1. Layer Audit",
        "body": "exporter = DWGExporter()\nxlsx = exporter.convert(\"drawing.dwg\")\nlayers = exporter.get_layers(str(xlsx))\n\n# Check for non-standard layers\nstandard_layers = ['0', 'WALLS', 'DOORS', 'WINDOWS', 'DIMENSIONS']\nnon_standard = layers[~layers['Layer'].isin(standard_layers)]\nprint(\"Non-standard layers:\", non_standard['Layer'].tolist())"
      },
      {
        "title": "2. Block Schedule",
        "body": "# Extract all door blocks with attributes\ndoors = exporter.extract_block_attributes(str(xlsx), \"DOOR\")\nprint(doors[['Block_Handle', 'Attr_DOOR_TYPE', 'Attr_DOOR_SIZE']])"
      },
      {
        "title": "3. Drawing Comparison",
        "body": "analyzer = DWGAnalyzer(exporter)\ndiff = analyzer.compare_drawings(\"rev1.dwg\", \"rev2.dwg\")\nprint(f\"Entities added: {diff['entity_count_diff']}\")\nprint(f\"New layers: {diff['layers_added']}\")"
      },
      {
        "title": "Integration with DDC Pipeline",
        "body": "# Full pipeline: DWG → Excel → Analysis → Report\nfrom dwg_exporter import DWGExporter, DWGAnalyzer\n\n# 1. Convert DWG\nexporter = DWGExporter(\"C:/DDC/DwgExporter.exe\")\nxlsx = exporter.convert(\"project.dwg\")\n\n# 2. Analyze structure\nanalyzer = DWGAnalyzer(exporter)\nanalysis = analyzer.analyze_drawing_structure(\"project.dwg\")\n\n# 3. Generate report\nprint(f\"Drawing: {analysis['file']}\")\nprint(f\"Entities: {analysis['total_entities']}\")\nprint(f\"Layers: {len(analysis['layers'])}\")\nprint(f\"Blocks: {len(analysis['blocks'])}\")"
      },
      {
        "title": "Best Practices",
        "body": "Check DWG version - Older files may have limited data\nValidate layer structure - Clean up before processing\nHandle external references - Bind xrefs if needed\nBatch overnight - Large files take time\nVerify entity counts - Compare with AutoCAD if possible"
      },
      {
        "title": "Resources",
        "body": "GitHub: cad2data Pipeline\nVideo Tutorial: DWG to Excel Pipeline\nDDC Book: Chapter 2.4 - CAD Data Extraction"
      }
    ],
    "body": "DWG to Excel Conversion\nBusiness Case\nProblem Statement\n\nAutoCAD DWG files contain valuable project data locked in proprietary format:\n\nLayer structures with drawing organization\nBlock references with attribute data\nText annotations and dimensions\nGeometric entities (lines, polylines, arcs)\nExternal references (xrefs)\n\nExtracting this data typically requires AutoCAD licenses or complex programming.\n\nSolution\n\nDwgExporter.exe converts DWG files to structured Excel databases offline, without Autodesk licenses.\n\nBusiness Value\nZero license cost - No AutoCAD license required\nLegacy support - Reads DWG files from 1983 to 2026\nData extraction - Layers, blocks, attributes, text, geometry\nPDF export - Generate drawings from DWG layouts\nBatch processing - Convert thousands of DWG files\nTechnical Implementation\nCLI Syntax\nDwgExporter.exe <input_dwg> [options]\n\nOutput Formats\nOutput\tDescription\n.xlsx\tExcel database with all entities\n.pdf\tPDF drawings from layouts\nSupported Versions\nVersion Range\tDescription\nR12 (1992)\tLegacy DWG\nR14 (1997)\tAutoCAD 14\n2000-2002\tDWG 2000 format\n2004-2006\tDWG 2004 format\n2007-2009\tDWG 2007 format\n2010-2012\tDWG 2010 format\n2013-2017\tDWG 2013 format\n2018-2026\tDWG 2018 format\nExamples\n# Basic conversion\nDwgExporter.exe \"C:\\Projects\\FloorPlan.dwg\"\n\n# Export with PDF drawings\nDwgExporter.exe \"C:\\Projects\\FloorPlan.dwg\" sheets2pdf\n\n# Batch processing all DWG in folder\nfor /R \"C:\\Projects\" %f in (*.dwg) do DwgExporter.exe \"%f\"\n\n# PowerShell batch conversion\nGet-ChildItem \"C:\\Projects\\*.dwg\" -Recurse | ForEach-Object {\n    & \"C:\\DDC\\DwgExporter.exe\" $_.FullName\n}\n\nPython Integration\nimport subprocess\nimport pandas as pd\nfrom pathlib import Path\nfrom typing import List, Optional, Dict, Any\nfrom dataclasses import dataclass\nfrom enum import Enum\n\n\nclass DWGEntityType(Enum):\n    \"\"\"DWG entity types.\"\"\"\n    LINE = \"LINE\"\n    POLYLINE = \"POLYLINE\"\n    LWPOLYLINE = \"LWPOLYLINE\"\n    CIRCLE = \"CIRCLE\"\n    ARC = \"ARC\"\n    ELLIPSE = \"ELLIPSE\"\n    SPLINE = \"SPLINE\"\n    TEXT = \"TEXT\"\n    MTEXT = \"MTEXT\"\n    DIMENSION = \"DIMENSION\"\n    INSERT = \"INSERT\"  # Block reference\n    HATCH = \"HATCH\"\n    SOLID = \"SOLID\"\n    POINT = \"POINT\"\n    ATTRIB = \"ATTRIB\"\n    ATTDEF = \"ATTDEF\"\n\n\n@dataclass\nclass DWGEntity:\n    \"\"\"Represents a DWG entity.\"\"\"\n    handle: str\n    entity_type: str\n    layer: str\n    color: int\n    linetype: str\n    lineweight: float\n\n    # Geometry (depends on entity type)\n    start_x: Optional[float] = None\n    start_y: Optional[float] = None\n    end_x: Optional[float] = None\n    end_y: Optional[float] = None\n\n    # Block reference data\n    block_name: Optional[str] = None\n    rotation: Optional[float] = None\n    scale_x: Optional[float] = None\n    scale_y: Optional[float] = None\n\n    # Text data\n    text_content: Optional[str] = None\n    text_height: Optional[float] = None\n\n\n@dataclass\nclass DWGBlock:\n    \"\"\"Represents a DWG block definition.\"\"\"\n    name: str\n    base_point_x: float\n    base_point_y: float\n    entity_count: int\n    is_dynamic: bool\n    attributes: List[str]\n\n\n@dataclass\nclass DWGLayer:\n    \"\"\"Represents a DWG layer.\"\"\"\n    name: str\n    color: int\n    linetype: str\n    is_on: bool\n    is_frozen: bool\n    is_locked: bool\n    lineweight: float\n    entity_count: int\n\n\nclass DWGExporter:\n    \"\"\"DWG to Excel converter using DDC DwgExporter CLI.\"\"\"\n\n    def __init__(self, exporter_path: str = \"DwgExporter.exe\"):\n        self.exporter = Path(exporter_path)\n        if not self.exporter.exists():\n            raise FileNotFoundError(f\"DwgExporter not found: {exporter_path}\")\n\n    def convert(self, dwg_file: str,\n                export_pdf: bool = False) -> Path:\n        \"\"\"Convert DWG file to Excel.\"\"\"\n        dwg_path = Path(dwg_file)\n        if not dwg_path.exists():\n            raise FileNotFoundError(f\"DWG file not found: {dwg_file}\")\n\n        cmd = [str(self.exporter), str(dwg_path)]\n        if export_pdf:\n            cmd.append(\"sheets2pdf\")\n\n        result = subprocess.run(cmd, capture_output=True, text=True)\n\n        if result.returncode != 0:\n            raise RuntimeError(f\"Export failed: {result.stderr}\")\n\n        # Output file is same name with .xlsx extension\n        return dwg_path.with_suffix('.xlsx')\n\n    def batch_convert(self, folder: str,\n                      include_subfolders: bool = True,\n                      export_pdf: bool = False) -> List[Dict[str, Any]]:\n        \"\"\"Convert all DWG files in folder.\"\"\"\n        folder_path = Path(folder)\n        pattern = \"**/*.dwg\" if include_subfolders else \"*.dwg\"\n\n        results = []\n        for dwg_file in folder_path.glob(pattern):\n            try:\n                output = self.convert(str(dwg_file), export_pdf)\n                results.append({\n                    'input': str(dwg_file),\n                    'output': str(output),\n                    'status': 'success'\n                })\n                print(f\"✓ Converted: {dwg_file.name}\")\n            except Exception as e:\n                results.append({\n                    'input': str(dwg_file),\n                    'output': None,\n                    'status': 'failed',\n                    'error': str(e)\n                })\n                print(f\"✗ Failed: {dwg_file.name} - {e}\")\n\n        return results\n\n    def read_entities(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Read converted Excel as DataFrame.\"\"\"\n        xlsx_path = Path(xlsx_file)\n        if not xlsx_path.exists():\n            raise FileNotFoundError(f\"Excel file not found: {xlsx_file}\")\n\n        return pd.read_excel(xlsx_file, sheet_name=\"Elements\")\n\n    def get_layers(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Get layer summary from converted file.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        if 'Layer' not in df.columns:\n            raise ValueError(\"Layer column not found in data\")\n\n        summary = df.groupby('Layer').agg({\n            'Handle': 'count'\n        }).reset_index()\n        summary.columns = ['Layer', 'Entity_Count']\n        return summary.sort_values('Entity_Count', ascending=False)\n\n    def get_blocks(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Get block reference summary.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Filter to INSERT entities (block references)\n        blocks = df[df['EntityType'] == 'INSERT']\n\n        if blocks.empty:\n            return pd.DataFrame(columns=['Block_Name', 'Count'])\n\n        summary = blocks.groupby('BlockName').agg({\n            'Handle': 'count'\n        }).reset_index()\n        summary.columns = ['Block_Name', 'Count']\n        return summary.sort_values('Count', ascending=False)\n\n    def get_text_content(self, xlsx_file: str) -> pd.DataFrame:\n        \"\"\"Extract all text content from DWG.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Filter to text entities\n        text_types = ['TEXT', 'MTEXT', 'ATTRIB']\n        texts = df[df['EntityType'].isin(text_types)]\n\n        if 'TextContent' in texts.columns:\n            return texts[['Handle', 'EntityType', 'Layer', 'TextContent']].copy()\n        return texts[['Handle', 'EntityType', 'Layer']].copy()\n\n    def get_entity_statistics(self, xlsx_file: str) -> Dict[str, int]:\n        \"\"\"Get entity type statistics.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        if 'EntityType' not in df.columns:\n            return {}\n\n        return df['EntityType'].value_counts().to_dict()\n\n    def extract_block_attributes(self, xlsx_file: str,\n                                  block_name: str) -> pd.DataFrame:\n        \"\"\"Extract attributes from specific block type.\"\"\"\n        df = self.read_entities(xlsx_file)\n\n        # Find block references\n        blocks = df[(df['EntityType'] == 'INSERT') &\n                    (df['BlockName'] == block_name)]\n\n        # Find associated attributes\n        # Attributes typically follow their parent INSERT in handle order\n        result_data = []\n\n        for _, block in blocks.iterrows():\n            block_handle = block['Handle']\n            block_data = {\n                'Block_Handle': block_handle,\n                'X': block.get('InsertX', 0),\n                'Y': block.get('InsertY', 0),\n                'Rotation': block.get('Rotation', 0)\n            }\n\n            # Add any attribute columns\n            for col in df.columns:\n                if col.startswith('Attr_'):\n                    block_data[col] = block.get(col)\n\n            result_data.append(block_data)\n\n        return pd.DataFrame(result_data)\n\n\nclass DWGAnalyzer:\n    \"\"\"Advanced DWG analysis tools.\"\"\"\n\n    def __init__(self, exporter: DWGExporter):\n        self.exporter = exporter\n\n    def analyze_drawing_structure(self, dwg_file: str) -> Dict[str, Any]:\n        \"\"\"Analyze complete drawing structure.\"\"\"\n        xlsx = self.exporter.convert(dwg_file)\n        df = self.exporter.read_entities(str(xlsx))\n\n        analysis = {\n            'file': dwg_file,\n            'total_entities': len(df),\n            'layers': self.exporter.get_layers(str(xlsx)).to_dict('records'),\n            'entity_types': self.exporter.get_entity_statistics(str(xlsx)),\n            'blocks': self.exporter.get_blocks(str(xlsx)).to_dict('records')\n        }\n\n        # Calculate extents if coordinates available\n        if 'X' in df.columns and 'Y' in df.columns:\n            analysis['extents'] = {\n                'min_x': df['X'].min(),\n                'max_x': df['X'].max(),\n                'min_y': df['Y'].min(),\n                'max_y': df['Y'].max()\n            }\n\n        return analysis\n\n    def compare_drawings(self, dwg1: str, dwg2: str) -> Dict[str, Any]:\n        \"\"\"Compare two DWG files.\"\"\"\n        xlsx1 = self.exporter.convert(dwg1)\n        xlsx2 = self.exporter.convert(dwg2)\n\n        df1 = self.exporter.read_entities(str(xlsx1))\n        df2 = self.exporter.read_entities(str(xlsx2))\n\n        layers1 = set(df1['Layer'].unique()) if 'Layer' in df1.columns else set()\n        layers2 = set(df2['Layer'].unique()) if 'Layer' in df2.columns else set()\n\n        return {\n            'file1': dwg1,\n            'file2': dwg2,\n            'entity_count_diff': len(df2) - len(df1),\n            'layers_added': list(layers2 - layers1),\n            'layers_removed': list(layers1 - layers2),\n            'common_layers': list(layers1 & layers2)\n        }\n\n    def find_duplicates(self, xlsx_file: str,\n                        tolerance: float = 0.001) -> pd.DataFrame:\n        \"\"\"Find duplicate entities at same location.\"\"\"\n        df = self.exporter.read_entities(xlsx_file)\n\n        if 'X' not in df.columns or 'Y' not in df.columns:\n            return pd.DataFrame()\n\n        # Round coordinates for grouping\n        df['X_rounded'] = (df['X'] / tolerance).round() * tolerance\n        df['Y_rounded'] = (df['Y'] / tolerance).round() * tolerance\n\n        # Find duplicates\n        duplicates = df[df.duplicated(\n            subset=['EntityType', 'Layer', 'X_rounded', 'Y_rounded'],\n            keep=False\n        )]\n\n        return duplicates.sort_values(['X_rounded', 'Y_rounded'])\n\n\n# Convenience functions\ndef convert_dwg_to_excel(dwg_file: str,\n                         exporter_path: str = \"DwgExporter.exe\") -> str:\n    \"\"\"Quick conversion of DWG to Excel.\"\"\"\n    exporter = DWGExporter(exporter_path)\n    output = exporter.convert(dwg_file)\n    return str(output)\n\n\ndef batch_convert_dwg(folder: str,\n                      exporter_path: str = \"DwgExporter.exe\",\n                      include_subfolders: bool = True) -> List[str]:\n    \"\"\"Batch convert all DWG files in folder.\"\"\"\n    exporter = DWGExporter(exporter_path)\n    results = exporter.batch_convert(folder, include_subfolders)\n    return [r['output'] for r in results if r['status'] == 'success']\n\nOutput Structure\nExcel Sheets\nSheet\tContent\nElements\tAll DWG entities with properties\nLayers\tLayer definitions\nBlocks\tBlock definitions\nLayouts\tDrawing layouts/sheets\nEntity Columns\nColumn\tType\tDescription\nHandle\tstring\tUnique entity handle\nEntityType\tstring\tLINE, CIRCLE, INSERT, etc.\nLayer\tstring\tLayer name\nColor\tint\tColor index (0-256)\nLinetype\tstring\tLinetype name\nLineweight\tfloat\tLine weight in mm\nX, Y, Z\tfloat\tEntity coordinates\nBlockName\tstring\tFor INSERT entities\nTextContent\tstring\tFor TEXT/MTEXT\nQuick Start\n# Initialize exporter\nexporter = DWGExporter(\"C:/DDC/DwgExporter.exe\")\n\n# Convert single file\nxlsx = exporter.convert(\"C:/Projects/Plan.dwg\")\nprint(f\"Output: {xlsx}\")\n\n# Read and analyze\ndf = exporter.read_entities(str(xlsx))\nprint(f\"Total entities: {len(df)}\")\n\n# Get layer statistics\nlayers = exporter.get_layers(str(xlsx))\nprint(layers)\n\n# Get block usage\nblocks = exporter.get_blocks(str(xlsx))\nprint(blocks)\n\n# Extract text annotations\ntexts = exporter.get_text_content(str(xlsx))\nfor _, row in texts.iterrows():\n    print(f\"{row['Layer']}: {row.get('TextContent', 'N/A')}\")\n\nCommon Use Cases\n1. Layer Audit\nexporter = DWGExporter()\nxlsx = exporter.convert(\"drawing.dwg\")\nlayers = exporter.get_layers(str(xlsx))\n\n# Check for non-standard layers\nstandard_layers = ['0', 'WALLS', 'DOORS', 'WINDOWS', 'DIMENSIONS']\nnon_standard = layers[~layers['Layer'].isin(standard_layers)]\nprint(\"Non-standard layers:\", non_standard['Layer'].tolist())\n\n2. Block Schedule\n# Extract all door blocks with attributes\ndoors = exporter.extract_block_attributes(str(xlsx), \"DOOR\")\nprint(doors[['Block_Handle', 'Attr_DOOR_TYPE', 'Attr_DOOR_SIZE']])\n\n3. Drawing Comparison\nanalyzer = DWGAnalyzer(exporter)\ndiff = analyzer.compare_drawings(\"rev1.dwg\", \"rev2.dwg\")\nprint(f\"Entities added: {diff['entity_count_diff']}\")\nprint(f\"New layers: {diff['layers_added']}\")\n\nIntegration with DDC Pipeline\n# Full pipeline: DWG → Excel → Analysis → Report\nfrom dwg_exporter import DWGExporter, DWGAnalyzer\n\n# 1. Convert DWG\nexporter = DWGExporter(\"C:/DDC/DwgExporter.exe\")\nxlsx = exporter.convert(\"project.dwg\")\n\n# 2. Analyze structure\nanalyzer = DWGAnalyzer(exporter)\nanalysis = analyzer.analyze_drawing_structure(\"project.dwg\")\n\n# 3. Generate report\nprint(f\"Drawing: {analysis['file']}\")\nprint(f\"Entities: {analysis['total_entities']}\")\nprint(f\"Layers: {len(analysis['layers'])}\")\nprint(f\"Blocks: {len(analysis['blocks'])}\")\n\nBest Practices\nCheck DWG version - Older files may have limited data\nValidate layer structure - Clean up before processing\nHandle external references - Bind xrefs if needed\nBatch overnight - Large files take time\nVerify entity counts - Compare with AutoCAD if possible\nResources\nGitHub: cad2data Pipeline\nVideo Tutorial: DWG to Excel Pipeline\nDDC Book: Chapter 2.4 - CAD Data Extraction"
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/datadrivenconstruction/dwg-to-excel",
    "publisherUrl": "https://clawhub.ai/datadrivenconstruction/dwg-to-excel",
    "owner": "datadrivenconstruction",
    "version": "2.0.0",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/dwg-to-excel",
    "downloadUrl": "https://openagent3.xyz/downloads/dwg-to-excel",
    "agentUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent",
    "manifestUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/dwg-to-excel/agent.md"
  }
}