dxfupdate für surfaces
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+55
-9
@@ -55,7 +55,22 @@ def create_block_library(input_dir, output_file, config, logger=None):
|
||||
src_doc = ezdxf.readfile(filepath)
|
||||
src_msp = src_doc.modelspace()
|
||||
entities = list(src_msp)
|
||||
allowed_types = {"LINE", "LWPOLYLINE", "POLYLINE", "SPLINE", "CIRCLE", "ARC", "INSERT","ATTDEF"}
|
||||
allowed_types = {
|
||||
"LINE",
|
||||
"LWPOLYLINE",
|
||||
"POLYLINE",
|
||||
"SPLINE",
|
||||
"CIRCLE",
|
||||
"ARC",
|
||||
"INSERT",
|
||||
"ATTDEF",
|
||||
"SURFACE",
|
||||
"3DSURFACE",
|
||||
"EXTRUDEDSURFACE",
|
||||
"REVOLVEDSURFACE",
|
||||
"LOFTEDSURFACE",
|
||||
"SWEPTSURFACE",
|
||||
}
|
||||
filtered_entities = []
|
||||
|
||||
for e in entities:
|
||||
@@ -375,6 +390,27 @@ def calculate_block_bounding_box(block, doc, src_doc, filename,config):
|
||||
return bbox, (bbox.extmax.x -bbox.extmin.x, bbox.extmax.y -bbox.extmin.y),bbox.center
|
||||
|
||||
|
||||
def _bbox_from_virtual_entities(entity, doc, src_doc, filename, config, transform_matrix=None):
|
||||
"""
|
||||
Nutzt virtual_entities(), um komplexe Objekte (z.B. SURFACE) in
|
||||
auswertbare Geometrie zu zerlegen und darauf eine Bounding Box zu
|
||||
berechnen.
|
||||
"""
|
||||
v_bbox = BoundingBox()
|
||||
if not hasattr(entity, "virtual_entities"):
|
||||
return v_bbox
|
||||
try:
|
||||
for ve in entity.virtual_entities():
|
||||
ve_bbox = get_entity_bounding_box(
|
||||
ve, doc, src_doc, filename, config, transform_matrix
|
||||
)
|
||||
if ve_bbox and ve_bbox.has_data:
|
||||
v_bbox.extend(ve_bbox)
|
||||
except Exception as err:
|
||||
print(f"Fehler bei virtual_entities() für {entity.dxftype()}: {err}")
|
||||
return v_bbox
|
||||
|
||||
|
||||
def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=None):
|
||||
"""
|
||||
Berechnet die Bounding Box einer einzelnen Entity
|
||||
@@ -441,17 +477,19 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non
|
||||
|
||||
elif e.dxftype() == 'LWPOLYLINE':
|
||||
# Nutze virtuelle Entities (Linien/Bögen), inkl. Bulge-Unterstützung
|
||||
for ve in e.virtual_entities():
|
||||
ve_bbox = get_entity_bounding_box(ve, doc, src_doc, filename, transform_matrix)
|
||||
if ve_bbox and ve_bbox.has_data:
|
||||
bbox.extend(ve_bbox)
|
||||
ve_bbox = _bbox_from_virtual_entities(
|
||||
e, doc, src_doc, filename, config, transform_matrix
|
||||
)
|
||||
if ve_bbox.has_data:
|
||||
bbox.extend(ve_bbox)
|
||||
|
||||
elif e.dxftype() == 'POLYLINE':
|
||||
# 2D/3D Polylines ebenfalls über virtuelle Entities
|
||||
for ve in e.virtual_entities():
|
||||
ve_bbox = get_entity_bounding_box(ve, doc, src_doc, filename, transform_matrix)
|
||||
if ve_bbox and ve_bbox.has_data:
|
||||
bbox.extend(ve_bbox)
|
||||
ve_bbox = _bbox_from_virtual_entities(
|
||||
e, doc, src_doc, filename, config, transform_matrix
|
||||
)
|
||||
if ve_bbox.has_data:
|
||||
bbox.extend(ve_bbox)
|
||||
|
||||
elif e.dxftype() == 'SPLINE':
|
||||
# Approximation der Spline-Kurve
|
||||
@@ -482,6 +520,14 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non
|
||||
insert_point = transform_matrix.transform(insert_point)
|
||||
|
||||
|
||||
elif e.dxftype().endswith('SURFACE'):
|
||||
# Viele Surface-Typen liefern ihre Proxy-Geometrie über virtual_entities()
|
||||
ve_bbox = _bbox_from_virtual_entities(
|
||||
e, doc, src_doc, filename, config, transform_matrix
|
||||
)
|
||||
if ve_bbox.has_data:
|
||||
bbox.extend(ve_bbox)
|
||||
|
||||
elif e.dxftype() == 'INSERT':
|
||||
# INSERT: Block-Inhalt mit Transformation berücksichtigen
|
||||
insert_bbox = calculate_insert_bounding_box(e, doc,src_doc,filename,config, transform_matrix)
|
||||
|
||||
Reference in New Issue
Block a user