power_grid / sample.txt
Silly98's picture
Update sample.txt
c8e7a71 verified
import ezdxf
from collections import Counter
def count_components_with_details(file_path):
try:
doc = ezdxf.readfile(file_path)
inventory = []
for layout in doc.layouts:
for insert in layout.query('INSERT'):
name = insert.dxf.name
# Filter out system/meta blocks
if name.startswith('*') or name == 'WD_M' or 'TB' in name.upper() or 'TTLB' in name.upper():
continue
# 1. GET THE PICK POINT (Insertion Point)
# Returns a Vector object (x, y, z)
ip = insert.dxf.insert
pick_point = f"({ip.x:.2f}, {ip.y:.2f})"
# 2. Extract attributes
raw_attribs = {att.dxf.tag: att.dxf.text for att in insert.attribs if att.dxf.text.strip()}
attr_str = " | ".join([f"{k}: {v}" for k, v in raw_attribs.items()])
if not attr_str:
attr_str = "(No Attributes)"
# We store the pick point along with name and attributes
inventory.append((name, pick_point, attr_str))
print(f"=== DETAILED INVENTORY FOR: {file_path} ===")
print(f"TOTAL COMPONENTS: {len(inventory)}")
print("-" * 120)
print(f"{'Block Name':<20} | {'Pick Point (X,Y)':<18} | {'Attribute Details'}")
print("-" * 120)
for name, p_point, attrs in inventory:
print(f"{name:<20} | {p_point:<18} | {attrs}")
except Exception as e:
print(f"Error: {e}")
# Usage
file_path = r"C:\Users\navinshrivatsan\Desktop\dxf_one_line_drawings\NRE-EC-101.0.dxf"
count_components_with_details(file_path)