Layer 0 in config aufgenommen. Dort waren die Rahmen, easy.json nicht mehr mit im Versionsverwaltungssystem verwalten. Kann leicht aus easy.dxf gewonnen werden.

This commit is contained in:
2025-05-30 19:09:58 +02:00
parent dec2898fb2
commit 6fef1c5f5a
6 changed files with 75 additions and 201 deletions
+61 -13
View File
@@ -154,18 +154,66 @@ def copy_layers_into_dxf_by_filter(dxf_source: ezdxf.document.Drawing, dxf_targe
msp_target = dxf_target.modelspace()
subdist_layers = list(config.items('GetPos-Layer_Distributors'))
rack_layers = list(config.items('GetPos-Layer_Racks'))
equipment_layers = list(config.items('GetPos-Layer_Equipment'))
tunnel_layers = list(config.items('GetPos-Layer_Tunnel'))
subdist_layers = set(config.options('GetPos-Layer_Distributors'))
rack_layers = set(config.options('GetPos-Layer_Racks'))
equipment_layers = set(config.options('GetPos-Layer_Equipment'))
tunnel_layers = set(config.options('GetPos-Layer_Tunnel'))
layernames = list()
layernames.extend(subdist_layers)
layernames.extend(rack_layers)
layernames.extend(equipment_layers)
layernames.extend(tunnel_layers)
layernames = set()
layernames.update(subdist_layers)
layernames.update(rack_layers)
layernames.update(equipment_layers)
layernames.update(tunnel_layers)
for (layername,v) in layernames:
# # welche Texte existieren
# for layername in layernames:
# selectstr = f'MTEXT[layer=="{layername}"]'
# for text in msp_source.query(selectstr):
# inhalt = text.dxf.text
# position = text.dxf.insert
# print(f"Text: '{inhalt}' an Position: {position} auf Layer: {layername}")
# text_entity = text.copy()
# msp_target.add_entity(text_entity)
layer_names_inside = dxf_source.layers
alle_block_defs = set(dxf_source.blocks.block_names())
verwendete = {insert.dxf.name for insert in msp_source.query("INSERT")}
# 1. Textstyles kopieren
for style in dxf_source.styles:
if style.dxf.name not in dxf_target.styles:
dxf_target.styles.new(name=style.dxf.name)
# 2. Bestimmte alle Blockdefinitionen
used_block_names = set()
for insert in msp_source.query("INSERT"):
block_name = insert.dxf.name
used_block_names.add(block_name)
# print(f"Blockname: {block_name} | Layer: {insert.dxf.layer} | Position: {insert.dxf.insert}")
# block = dxf_source.blocks.get(block_name)
# print(f"Inhalte von Block '{block_name}':")
# for entity in block:
# print(f" Typ: {entity.dxftype()}, Layer: {entity.dxf.layer}")
# for attrib in insert.attribs:
# if len(insert.attribs) == 0:
# continue # Überspringe Blöcke ohne Attribute
# print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}")
# has_mtext = any(e.dxftype() == "MTEXT" for e in block)
# if has_mtext:
# print(f"Block '{block_name}' enthält MTEXT:")
# 3. Blockdefinitionen kopieren
for block_name in used_block_names:
if block_name not in dxf_target.blocks:
block = dxf_source.blocks.get(block_name)
new_block = dxf_target.blocks.new(name=block_name)
new_block.block.dxf.base_point = block.block.dxf.base_point
for e in block:
new_block.add_entity(e.copy())
# 4. Filter-Layernamen bestimmen
for layername in layernames:
if layername not in dxf_source.layers:
continue
# Falls der Layer noch nicht im Zieldokument existiert, neu anlegen
@@ -177,13 +225,13 @@ def copy_layers_into_dxf_by_filter(dxf_source: ezdxf.document.Drawing, dxf_targe
linetype=quelle_layer.dxf.linetype,
lineweight=quelle_layer.dxf.lineweight
)
# Alle Entities auf diesem Layer kopieren
for entity in msp_source.query(f"*[layer=='{layername}']"):
entities = msp_source.query(f"*[layer=='{layername}']")
for entity in entities:
msp_target.add_entity(entity.copy())
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
parser.add_argument('-f', '--filename', action='store', required=True, help='this json file contains all cables and its coordinates which should be drawn. Saved with an unique timestamp', metavar='myfile.json')
+9 -7
View File
@@ -50,22 +50,24 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
id = ""
ld = dict()
for attrib in insert.attribs:
attr_tag = attrib.dxf.tag
attr_text = attrib.dxf.text
if len(insert.attribs) == 0:
continue # Überspringe Blöcke ohne Attribute
#print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}")
ld[attrib.dxf.tag] = attrib.dxf.text
if attrib.dxf.tag == "IO":
id = attrib.dxf.text
ld[attr_tag] = attr_text
if attr_tag == "IO":
id = attr_text
#print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben
ld["pos"] = (round(pos.x, 1), round(pos.y, 1))
if attrib.dxf.tag == "B":
if attr_tag == "B":
for spec in SpecialKeys:
if spec in attrib.dxf.text:
id = attrib.dxf.text
if spec in attr_text:
id = attr_text
#print(f"-- coord {attrib.dxf.text} --: {attrib.dxf.insert}")
if attrib.dxf.tag == "REALE_POSITION" and attrib.dxf.text == "x":
if attr_tag == "REALE_POSITION" and attr_text == "x":
#print(f"-- coord real --: {attrib.dxf.insert}")
pos = attrib.dxf.insert #Position Ecke unten links von "x"-Marker auslesen