Dwg To Excel
/install dwg-to-excel
\r \r
DWG to Excel Conversion\r
\r
Business Case\r
\r
Problem Statement\r
AutoCAD DWG files contain valuable project data locked in proprietary format:\r
- Layer structures with drawing organization\r
- Block references with attribute data\r
- Text annotations and dimensions\r
- Geometric entities (lines, polylines, arcs)\r
- External references (xrefs)\r \r Extracting this data typically requires AutoCAD licenses or complex programming.\r \r
Solution\r
DwgExporter.exe converts DWG files to structured Excel databases offline, without Autodesk licenses.\r \r
Business Value\r
- Zero license cost - No AutoCAD license required\r
- Legacy support - Reads DWG files from 1983 to 2026\r
- Data extraction - Layers, blocks, attributes, text, geometry\r
- PDF export - Generate drawings from DWG layouts\r
- Batch processing - Convert thousands of DWG files\r \r
Technical Implementation\r
\r
CLI Syntax\r
DwgExporter.exe \x3Cinput_dwg> [options]\r
```\r
\r
### Output Formats\r
| Output | Description |\r
|--------|-------------|\r
| `.xlsx` | Excel database with all entities |\r
| `.pdf` | PDF drawings from layouts |\r
\r
### Supported Versions\r
| Version Range | Description |\r
|---------------|-------------|\r
| R12 (1992) | Legacy DWG |\r
| R14 (1997) | AutoCAD 14 |\r
| 2000-2002 | DWG 2000 format |\r
| 2004-2006 | DWG 2004 format |\r
| 2007-2009 | DWG 2007 format |\r
| 2010-2012 | DWG 2010 format |\r
| 2013-2017 | DWG 2013 format |\r
| 2018-2026 | DWG 2018 format |\r
\r
### Examples\r
\r
```bash\r
# Basic conversion\r
DwgExporter.exe "C:\Projects\FloorPlan.dwg"\r
\r
# Export with PDF drawings\r
DwgExporter.exe "C:\Projects\FloorPlan.dwg" sheets2pdf\r
\r
# Batch processing all DWG in folder\r
for /R "C:\Projects" %f in (*.dwg) do DwgExporter.exe "%f"\r
\r
# PowerShell batch conversion\r
Get-ChildItem "C:\Projects\*.dwg" -Recurse | ForEach-Object {\r
& "C:\DDC\DwgExporter.exe" $_.FullName\r
}\r
```\r
\r
### Python Integration\r
\r
```python\r
import subprocess\r
import pandas as pd\r
from pathlib import Path\r
from typing import List, Optional, Dict, Any\r
from dataclasses import dataclass\r
from enum import Enum\r
\r
\r
class DWGEntityType(Enum):\r
"""DWG entity types."""\r
LINE = "LINE"\r
POLYLINE = "POLYLINE"\r
LWPOLYLINE = "LWPOLYLINE"\r
CIRCLE = "CIRCLE"\r
ARC = "ARC"\r
ELLIPSE = "ELLIPSE"\r
SPLINE = "SPLINE"\r
TEXT = "TEXT"\r
MTEXT = "MTEXT"\r
DIMENSION = "DIMENSION"\r
INSERT = "INSERT" # Block reference\r
HATCH = "HATCH"\r
SOLID = "SOLID"\r
POINT = "POINT"\r
ATTRIB = "ATTRIB"\r
ATTDEF = "ATTDEF"\r
\r
\r
@dataclass\r
class DWGEntity:\r
"""Represents a DWG entity."""\r
handle: str\r
entity_type: str\r
layer: str\r
color: int\r
linetype: str\r
lineweight: float\r
\r
# Geometry (depends on entity type)\r
start_x: Optional[float] = None\r
start_y: Optional[float] = None\r
end_x: Optional[float] = None\r
end_y: Optional[float] = None\r
\r
# Block reference data\r
block_name: Optional[str] = None\r
rotation: Optional[float] = None\r
scale_x: Optional[float] = None\r
scale_y: Optional[float] = None\r
\r
# Text data\r
text_content: Optional[str] = None\r
text_height: Optional[float] = None\r
\r
\r
@dataclass\r
class DWGBlock:\r
"""Represents a DWG block definition."""\r
name: str\r
base_point_x: float\r
base_point_y: float\r
entity_count: int\r
is_dynamic: bool\r
attributes: List[str]\r
\r
\r
@dataclass\r
class DWGLayer:\r
"""Represents a DWG layer."""\r
name: str\r
color: int\r
linetype: str\r
is_on: bool\r
is_frozen: bool\r
is_locked: bool\r
lineweight: float\r
entity_count: int\r
\r
\r
class DWGExporter:\r
"""DWG to Excel converter using DDC DwgExporter CLI."""\r
\r
def __init__(self, exporter_path: str = "DwgExporter.exe"):\r
self.exporter = Path(exporter_path)\r
if not self.exporter.exists():\r
raise FileNotFoundError(f"DwgExporter not found: {exporter_path}")\r
\r
def convert(self, dwg_file: str,\r
export_pdf: bool = False) -> Path:\r
"""Convert DWG file to Excel."""\r
dwg_path = Path(dwg_file)\r
if not dwg_path.exists():\r
raise FileNotFoundError(f"DWG file not found: {dwg_file}")\r
\r
cmd = [str(self.exporter), str(dwg_path)]\r
if export_pdf:\r
cmd.append("sheets2pdf")\r
\r
result = subprocess.run(cmd, capture_output=True, text=True)\r
\r
if result.returncode != 0:\r
raise RuntimeError(f"Export failed: {result.stderr}")\r
\r
# Output file is same name with .xlsx extension\r
return dwg_path.with_suffix('.xlsx')\r
\r
def batch_convert(self, folder: str,\r
include_subfolders: bool = True,\r
export_pdf: bool = False) -> List[Dict[str, Any]]:\r
"""Convert all DWG files in folder."""\r
folder_path = Path(folder)\r
pattern = "**/*.dwg" if include_subfolders else "*.dwg"\r
\r
results = []\r
for dwg_file in folder_path.glob(pattern):\r
try:\r
output = self.convert(str(dwg_file), export_pdf)\r
results.append({\r
'input': str(dwg_file),\r
'output': str(output),\r
'status': 'success'\r
})\r
print(f"✓ Converted: {dwg_file.name}")\r
except Exception as e:\r
results.append({\r
'input': str(dwg_file),\r
'output': None,\r
'status': 'failed',\r
'error': str(e)\r
})\r
print(f"✗ Failed: {dwg_file.name} - {e}")\r
\r
return results\r
\r
def read_entities(self, xlsx_file: str) -> pd.DataFrame:\r
"""Read converted Excel as DataFrame."""\r
xlsx_path = Path(xlsx_file)\r
if not xlsx_path.exists():\r
raise FileNotFoundError(f"Excel file not found: {xlsx_file}")\r
\r
return pd.read_excel(xlsx_file, sheet_name="Elements")\r
\r
def get_layers(self, xlsx_file: str) -> pd.DataFrame:\r
"""Get layer summary from converted file."""\r
df = self.read_entities(xlsx_file)\r
\r
if 'Layer' not in df.columns:\r
raise ValueError("Layer column not found in data")\r
\r
summary = df.groupby('Layer').agg({\r
'Handle': 'count'\r
}).reset_index()\r
summary.columns = ['Layer', 'Entity_Count']\r
return summary.sort_values('Entity_Count', ascending=False)\r
\r
def get_blocks(self, xlsx_file: str) -> pd.DataFrame:\r
"""Get block reference summary."""\r
df = self.read_entities(xlsx_file)\r
\r
# Filter to INSERT entities (block references)\r
blocks = df[df['EntityType'] == 'INSERT']\r
\r
if blocks.empty:\r
return pd.DataFrame(columns=['Block_Name', 'Count'])\r
\r
summary = blocks.groupby('BlockName').agg({\r
'Handle': 'count'\r
}).reset_index()\r
summary.columns = ['Block_Name', 'Count']\r
return summary.sort_values('Count', ascending=False)\r
\r
def get_text_content(self, xlsx_file: str) -> pd.DataFrame:\r
"""Extract all text content from DWG."""\r
df = self.read_entities(xlsx_file)\r
\r
# Filter to text entities\r
text_types = ['TEXT', 'MTEXT', 'ATTRIB']\r
texts = df[df['EntityType'].isin(text_types)]\r
\r
if 'TextContent' in texts.columns:\r
return texts[['Handle', 'EntityType', 'Layer', 'TextContent']].copy()\r
return texts[['Handle', 'EntityType', 'Layer']].copy()\r
\r
def get_entity_statistics(self, xlsx_file: str) -> Dict[str, int]:\r
"""Get entity type statistics."""\r
df = self.read_entities(xlsx_file)\r
\r
if 'EntityType' not in df.columns:\r
return {}\r
\r
return df['EntityType'].value_counts().to_dict()\r
\r
def extract_block_attributes(self, xlsx_file: str,\r
block_name: str) -> pd.DataFrame:\r
"""Extract attributes from specific block type."""\r
df = self.read_entities(xlsx_file)\r
\r
# Find block references\r
blocks = df[(df['EntityType'] == 'INSERT') &\r
(df['BlockName'] == block_name)]\r
\r
# Find associated attributes\r
# Attributes typically follow their parent INSERT in handle order\r
result_data = []\r
\r
for _, block in blocks.iterrows():\r
block_handle = block['Handle']\r
block_data = {\r
'Block_Handle': block_handle,\r
'X': block.get('InsertX', 0),\r
'Y': block.get('InsertY', 0),\r
'Rotation': block.get('Rotation', 0)\r
}\r
\r
# Add any attribute columns\r
for col in df.columns:\r
if col.startswith('Attr_'):\r
block_data[col] = block.get(col)\r
\r
result_data.append(block_data)\r
\r
return pd.DataFrame(result_data)\r
\r
\r
class DWGAnalyzer:\r
"""Advanced DWG analysis tools."""\r
\r
def __init__(self, exporter: DWGExporter):\r
self.exporter = exporter\r
\r
def analyze_drawing_structure(self, dwg_file: str) -> Dict[str, Any]:\r
"""Analyze complete drawing structure."""\r
xlsx = self.exporter.convert(dwg_file)\r
df = self.exporter.read_entities(str(xlsx))\r
\r
analysis = {\r
'file': dwg_file,\r
'total_entities': len(df),\r
'layers': self.exporter.get_layers(str(xlsx)).to_dict('records'),\r
'entity_types': self.exporter.get_entity_statistics(str(xlsx)),\r
'blocks': self.exporter.get_blocks(str(xlsx)).to_dict('records')\r
}\r
\r
# Calculate extents if coordinates available\r
if 'X' in df.columns and 'Y' in df.columns:\r
analysis['extents'] = {\r
'min_x': df['X'].min(),\r
'max_x': df['X'].max(),\r
'min_y': df['Y'].min(),\r
'max_y': df['Y'].max()\r
}\r
\r
return analysis\r
\r
def compare_drawings(self, dwg1: str, dwg2: str) -> Dict[str, Any]:\r
"""Compare two DWG files."""\r
xlsx1 = self.exporter.convert(dwg1)\r
xlsx2 = self.exporter.convert(dwg2)\r
\r
df1 = self.exporter.read_entities(str(xlsx1))\r
df2 = self.exporter.read_entities(str(xlsx2))\r
\r
layers1 = set(df1['Layer'].unique()) if 'Layer' in df1.columns else set()\r
layers2 = set(df2['Layer'].unique()) if 'Layer' in df2.columns else set()\r
\r
return {\r
'file1': dwg1,\r
'file2': dwg2,\r
'entity_count_diff': len(df2) - len(df1),\r
'layers_added': list(layers2 - layers1),\r
'layers_removed': list(layers1 - layers2),\r
'common_layers': list(layers1 & layers2)\r
}\r
\r
def find_duplicates(self, xlsx_file: str,\r
tolerance: float = 0.001) -> pd.DataFrame:\r
"""Find duplicate entities at same location."""\r
df = self.exporter.read_entities(xlsx_file)\r
\r
if 'X' not in df.columns or 'Y' not in df.columns:\r
return pd.DataFrame()\r
\r
# Round coordinates for grouping\r
df['X_rounded'] = (df['X'] / tolerance).round() * tolerance\r
df['Y_rounded'] = (df['Y'] / tolerance).round() * tolerance\r
\r
# Find duplicates\r
duplicates = df[df.duplicated(\r
subset=['EntityType', 'Layer', 'X_rounded', 'Y_rounded'],\r
keep=False\r
)]\r
\r
return duplicates.sort_values(['X_rounded', 'Y_rounded'])\r
\r
\r
# Convenience functions\r
def convert_dwg_to_excel(dwg_file: str,\r
exporter_path: str = "DwgExporter.exe") -> str:\r
"""Quick conversion of DWG to Excel."""\r
exporter = DWGExporter(exporter_path)\r
output = exporter.convert(dwg_file)\r
return str(output)\r
\r
\r
def batch_convert_dwg(folder: str,\r
exporter_path: str = "DwgExporter.exe",\r
include_subfolders: bool = True) -> List[str]:\r
"""Batch convert all DWG files in folder."""\r
exporter = DWGExporter(exporter_path)\r
results = exporter.batch_convert(folder, include_subfolders)\r
return [r['output'] for r in results if r['status'] == 'success']\r
```\r
\r
## Output Structure\r
\r
### Excel Sheets\r
| Sheet | Content |\r
|-------|---------|\r
| Elements | All DWG entities with properties |\r
| Layers | Layer definitions |\r
| Blocks | Block definitions |\r
| Layouts | Drawing layouts/sheets |\r
\r
### Entity Columns\r
| Column | Type | Description |\r
|--------|------|-------------|\r
| Handle | string | Unique entity handle |\r
| EntityType | string | LINE, CIRCLE, INSERT, etc. |\r
| Layer | string | Layer name |\r
| Color | int | Color index (0-256) |\r
| Linetype | string | Linetype name |\r
| Lineweight | float | Line weight in mm |\r
| X, Y, Z | float | Entity coordinates |\r
| BlockName | string | For INSERT entities |\r
| TextContent | string | For TEXT/MTEXT |\r
\r
## Quick Start\r
\r
```python\r
# Initialize exporter\r
exporter = DWGExporter("C:/DDC/DwgExporter.exe")\r
\r
# Convert single file\r
xlsx = exporter.convert("C:/Projects/Plan.dwg")\r
print(f"Output: {xlsx}")\r
\r
# Read and analyze\r
df = exporter.read_entities(str(xlsx))\r
print(f"Total entities: {len(df)}")\r
\r
# Get layer statistics\r
layers = exporter.get_layers(str(xlsx))\r
print(layers)\r
\r
# Get block usage\r
blocks = exporter.get_blocks(str(xlsx))\r
print(blocks)\r
\r
# Extract text annotations\r
texts = exporter.get_text_content(str(xlsx))\r
for _, row in texts.iterrows():\r
print(f"{row['Layer']}: {row.get('TextContent', 'N/A')}")\r
```\r
\r
## Common Use Cases\r
\r
### 1. Layer Audit\r
```python\r
exporter = DWGExporter()\r
xlsx = exporter.convert("drawing.dwg")\r
layers = exporter.get_layers(str(xlsx))\r
\r
# Check for non-standard layers\r
standard_layers = ['0', 'WALLS', 'DOORS', 'WINDOWS', 'DIMENSIONS']\r
non_standard = layers[~layers['Layer'].isin(standard_layers)]\r
print("Non-standard layers:", non_standard['Layer'].tolist())\r
```\r
\r
### 2. Block Schedule\r
```python\r
# Extract all door blocks with attributes\r
doors = exporter.extract_block_attributes(str(xlsx), "DOOR")\r
print(doors[['Block_Handle', 'Attr_DOOR_TYPE', 'Attr_DOOR_SIZE']])\r
```\r
\r
### 3. Drawing Comparison\r
```python\r
analyzer = DWGAnalyzer(exporter)\r
diff = analyzer.compare_drawings("rev1.dwg", "rev2.dwg")\r
print(f"Entities added: {diff['entity_count_diff']}")\r
print(f"New layers: {diff['layers_added']}")\r
```\r
\r
## Integration with DDC Pipeline\r
\r
```python\r
# Full pipeline: DWG → Excel → Analysis → Report\r
from dwg_exporter import DWGExporter, DWGAnalyzer\r
\r
# 1. Convert DWG\r
exporter = DWGExporter("C:/DDC/DwgExporter.exe")\r
xlsx = exporter.convert("project.dwg")\r
\r
# 2. Analyze structure\r
analyzer = DWGAnalyzer(exporter)\r
analysis = analyzer.analyze_drawing_structure("project.dwg")\r
\r
# 3. Generate report\r
print(f"Drawing: {analysis['file']}")\r
print(f"Entities: {analysis['total_entities']}")\r
print(f"Layers: {len(analysis['layers'])}")\r
print(f"Blocks: {len(analysis['blocks'])}")\r
```\r
\r
## Best Practices\r
\r
1. **Check DWG version** - Older files may have limited data\r
2. **Validate layer structure** - Clean up before processing\r
3. **Handle external references** - Bind xrefs if needed\r
4. **Batch overnight** - Large files take time\r
5. **Verify entity counts** - Compare with AutoCAD if possible\r
\r
## Resources\r
\r
- **GitHub**: [cad2data Pipeline](https://github.com/datadrivenconstruction/cad2data-Revit-IFC-DWG-DGN-pipeline-with-conversion-validation-qto)\r
- **Video Tutorial**: [DWG to Excel Pipeline](https://www.youtube.com/watch?v=jVU7vlMNTO0)\r
- **DDC Book**: Chapter 2.4 - CAD Data Extraction\r
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install dwg-to-excel - After installation, invoke the skill by name or use
/dwg-to-excel - Provide required inputs per the skill's parameter spec and get structured output
What is Dwg To Excel?
Convert AutoCAD DWG files (1983-2026) to Excel databases using DwgExporter CLI. Extract layers, blocks, attributes, and geometry data without Autodesk licenses. It is an AI Agent Skill for Claude Code / OpenClaw, with 1874 downloads so far.
How do I install Dwg To Excel?
Run "/install dwg-to-excel" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Dwg To Excel free?
Yes, Dwg To Excel is completely free (open-source). You can download, install and use it at no cost.
Which platforms does Dwg To Excel support?
Dwg To Excel is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Dwg To Excel?
It is built and maintained by datadrivenconstruction (@datadrivenconstruction); the current version is v2.0.0.