Optimierung der Bounding Box-Berechnung in dxf2lib.py: Vereinfachung der POLYLINE- und LWPOLYLINE-Logik, um die Berechnung der minimalen und maximalen Koordinaten zu verbessern. Anpassung der Blockerstellung, um die Geometrie korrekt zu verschieben.
This commit is contained in:
+15
-9
@@ -17,14 +17,16 @@ def get_bbox(entities):
|
|||||||
max_x, max_y = float('-inf'), float('-inf')
|
max_x, max_y = float('-inf'), float('-inf')
|
||||||
for e in entities:
|
for e in entities:
|
||||||
try:
|
try:
|
||||||
# Für POLYLINE-Entities: Bounding Box manuell berechnen
|
|
||||||
if e.dxftype() == "POLYLINE":
|
if e.dxftype() == "POLYLINE":
|
||||||
if hasattr(e, 'vertices') and len(e.vertices) > 0:
|
for vertex in e.vertices:
|
||||||
for vertex in e.vertices:
|
if hasattr(vertex.dxf, 'location'):
|
||||||
if hasattr(vertex, 'dxf') and hasattr(vertex.dxf, 'location'):
|
x, y = vertex.dxf.location.x, vertex.dxf.location.y
|
||||||
x, y = vertex.dxf.location.x, vertex.dxf.location.y
|
min_x, min_y = min(min_x, x), min(min_y, y)
|
||||||
min_x, min_y = min(min_x, x), min(min_y, y)
|
max_x, max_y = max(max_x, x), max(max_y, y)
|
||||||
max_x, max_y = max(max_x, x), max(max_y, y)
|
elif e.dxftype() == "LWPOLYLINE":
|
||||||
|
for x, y, *_ in e.get_points("xy"):
|
||||||
|
min_x, min_y = min(min_x, x), min(min_y, y)
|
||||||
|
max_x, max_y = max(max_x, x), max(max_y, y)
|
||||||
else:
|
else:
|
||||||
# Für andere Entity-Typen: Standard bbox() verwenden
|
# Für andere Entity-Typen: Standard bbox() verwenden
|
||||||
box = e.bbox()
|
box = e.bbox()
|
||||||
@@ -35,8 +37,10 @@ def get_bbox(entities):
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f" BBox Fehler für {e.dxftype()}: {err}")
|
print(f" BBox Fehler für {e.dxftype()}: {err}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if min_x == float('inf'):
|
if min_x == float('inf'):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Vec2((min_x + max_x) / 2, (min_y + max_y) / 2)
|
return Vec2((min_x + max_x) / 2, (min_y + max_y) / 2)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -101,11 +105,13 @@ if __name__ == "__main__":
|
|||||||
if name in doc.blocks:
|
if name in doc.blocks:
|
||||||
doc.blocks.delete_block(name)
|
doc.blocks.delete_block(name)
|
||||||
|
|
||||||
blk = doc.blocks.new(name=name, base_point=center)
|
blk = doc.blocks.new(name=name, base_point=(0,0))
|
||||||
|
|
||||||
for e in entities:
|
for e in entities:
|
||||||
try:
|
try:
|
||||||
blk.add_entity(e.copy())
|
cp = e.copy()
|
||||||
|
cp.translate(-center.x, -center.y, 0) # Geometrie verschieben!
|
||||||
|
blk.add_entity(cp)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Fehler in {filename}: {err}")
|
print(f"Fehler in {filename}: {err}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user