geändert wie ich den vorderen block layer definiere
This commit is contained in:
@@ -3,7 +3,7 @@ from ezdxf.entities import Line
|
||||
import math
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from typing import Optional
|
||||
from plant2dxf import import_block, get_layer
|
||||
import plant2dxf
|
||||
|
||||
|
||||
ATTR_TAG = "TeileId" # Attributtag im Block
|
||||
@@ -218,8 +218,8 @@ class Kreisel(BaseModel):
|
||||
rotation = math.degrees(math.atan2(p2_oben[1] - p1_oben[1], p2_oben[0] - p1_oben[0]))
|
||||
if drehrichtung == "GUZS":
|
||||
rotation += 180
|
||||
import_block("Richtungspfeil", lib_doc, doc)
|
||||
blockref_layer = get_layer(doc, lib_doc, "Richtungspfeil")
|
||||
plant2dxf.import_block("Richtungspfeil", lib_doc, doc)
|
||||
blockref_layer, color = plant2dxf.get_insert_color_layer(lib_doc, "Richtungspfeil")
|
||||
bref = msp.add_blockref("Richtungspfeil", (px, py,z1), dxfattribs={"rotation": rotation,"layer": blockref_layer})
|
||||
if verbose:
|
||||
print(f"[INFO] Drehrichtung '{drehrichtung}': Richtungspfeil oben bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}")
|
||||
@@ -231,8 +231,8 @@ class Kreisel(BaseModel):
|
||||
rotation = math.degrees(math.atan2(p2_unten[1] - p1_unten[1], p2_unten[0] - p1_unten[0]))
|
||||
if drehrichtung == "UZS":
|
||||
rotation += 180
|
||||
import_block("Richtungspfeil", lib_doc, doc)
|
||||
blockref_layer = get_layer(doc, lib_doc, "Richtungspfeil")
|
||||
plant2dxf.import_block("Richtungspfeil", lib_doc, doc)
|
||||
blockref_layer, color = plant2dxf.get_insert_color_layer( lib_doc, "Richtungspfeil")
|
||||
bref = msp.add_blockref("Richtungspfeil", (px, py, z1), dxfattribs={"rotation": rotation , "layer": blockref_layer})
|
||||
if verbose:
|
||||
print(f"[INFO] Drehrichtung '{drehrichtung}':Richtungspfeil unten bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}")
|
||||
+16
-45
@@ -238,7 +238,7 @@ def handle_ils_2_0_kreisel(msp, teileid, merkmale, x, y, doc, lib_doc, verbose,
|
||||
if i < len(positions):
|
||||
pos = (positions[i][0] + offset[0], positions[i][1] + offset[1], kreisel.hoehe)
|
||||
import_block(blockname, lib_doc, doc)
|
||||
blockref_layer = get_layer(doc, lib_doc, blockname)
|
||||
blockref_layer, color = get_insert_color_layer(lib_doc, blockname)
|
||||
bref = msp.add_blockref(blockname, pos, dxfattribs={"layer" : blockref_layer})
|
||||
bref.add_auto_attribs({ATTR_TAG: teileid})
|
||||
if verbose:
|
||||
@@ -249,15 +249,6 @@ def handle_ils_2_0_kreisel(msp, teileid, merkmale, x, y, doc, lib_doc, verbose,
|
||||
Kreisel.Kreisel.draw_kreisel_lines(msp, pos1, pos2, kreisel)
|
||||
Kreisel.Kreisel.draw_kreisel_drehrichtung_markierung(msp, pos1, pos2, kreisel, lib_doc, doc, verbose)
|
||||
|
||||
def handle_standard(msp, blocknames, teileid, x, y, lib_doc, doc, verbose):
|
||||
for blockname in blocknames:
|
||||
import_block(blockname, lib_doc, doc)
|
||||
blockref_layer = get_layer(doc, lib_doc, blockname)
|
||||
bref = msp.add_blockref(blockname, (x, y), dxfattribs={"layer": blockref_layer})
|
||||
bref.add_auto_attribs({ATTR_TAG: teileid})
|
||||
if verbose:
|
||||
print(f"[INFO] Block '{blockname}' (Standard) → {teileid} "
|
||||
f"({x:.1f}, {y:.1f})")
|
||||
|
||||
def handle_ils_2_0_eckrad(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein):
|
||||
import_block("AN8",lib_doc,doc)
|
||||
@@ -322,11 +313,13 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v
|
||||
block_separatoren = "S-LP"
|
||||
import_block(block_scanner,lib_doc,doc)
|
||||
import_block(block_separatoren,lib_doc,doc)
|
||||
layer_scan, color_scan = get_insert_color_layer(lib_doc, block_scanner)
|
||||
layer_separatioren, color_separatioren = get_insert_color_layer(lib_doc, block_separatoren)
|
||||
einsatz_zwischen =[ einsatz_fest[0],einsatz_fest[1],einsatz_fest[2]]
|
||||
anzahl =0
|
||||
while anzahl < separatoren:
|
||||
anzahl = anzahl + 1
|
||||
msp.add_blockref(block_separatoren,einsatz_zwischen)
|
||||
msp.add_blockref(block_separatoren,einsatz_zwischen, dxfattribs={"layer": layer_separatioren,"color": color_separatioren})
|
||||
if anzahl % modular == 0:
|
||||
einsatz_fest[1] = einsatz_fest[1] - 150
|
||||
einsatz_zwischen = einsatz_fest.copy()
|
||||
@@ -339,7 +332,7 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v
|
||||
anzahl =0
|
||||
while anzahl < scanner:
|
||||
anzahl = anzahl + 1
|
||||
msp.add_blockref(block_scanner,einsatz_zwischen)
|
||||
msp.add_blockref(block_scanner,einsatz_zwischen,dxfattribs={"layer": layer_scan,"color": color_scan})
|
||||
if anzahl % modular == 0:
|
||||
einsatz_fest[1] = einsatz_fest[1] - 150
|
||||
einsatz_zwischen = einsatz_fest.copy()
|
||||
@@ -601,7 +594,7 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v
|
||||
else:
|
||||
blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaehlle}_{drehung0}_{drehung1}_{hight_position}_{unterschiedlich}_{richtung2}_{verbunden_am_einen}"
|
||||
as_es_methoden.gefaellegerade_erstellung(x, y, doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, hoehe_gefaehlle,richtung2,drehung0, drehung1, laenge, hight_position,blockname,config)
|
||||
blockref_layer = get_layer(doc, lib_doc, blockname)
|
||||
blockref_layer, color = get_insert_color_layer(lib_doc, blockname)
|
||||
|
||||
bref =msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation, "layer": blockref_layer })
|
||||
a = bref.add_attrib(
|
||||
@@ -1417,38 +1410,16 @@ def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols,
|
||||
# Layer, auf dem der Insert liegt
|
||||
|
||||
|
||||
def get_layer(doc, lib_doc, blockname):
|
||||
if blockname in lib_doc.blocks:
|
||||
src = lib_doc.blocks[blockname]
|
||||
else:
|
||||
src = doc.blocks[blockname]
|
||||
try:
|
||||
used_layer_names = {e.dxf.layer for e in src if hasattr(e.dxf, "layer")}
|
||||
for layer_name in used_layer_names:
|
||||
if layer_name and layer_name not in doc.layers:
|
||||
try:
|
||||
src_layer = lib_doc.layers.get(layer_name)
|
||||
doc.layers.add(
|
||||
name=layer_name,
|
||||
color=getattr(src_layer.dxf, "color", None),
|
||||
linetype=getattr(src_layer.dxf, "linetype", None),
|
||||
lineweight=getattr(src_layer.dxf, "lineweight", None),
|
||||
)
|
||||
except Exception:
|
||||
# Fallback: Layer mit Standardwerten anlegen
|
||||
doc.layers.add(name=layer_name)
|
||||
except Exception:
|
||||
pass
|
||||
layer_counts = {}
|
||||
for e in src:
|
||||
ln = getattr(e.dxf, "layer", None)
|
||||
if not ln:
|
||||
continue
|
||||
if ln != "BOUNDING_BOX":
|
||||
layer_counts[ln] = layer_counts.get(ln, 0) + 1
|
||||
if layer_counts:
|
||||
blockref_layer = max(layer_counts.items(), key=lambda kv: kv[1])[0]
|
||||
return blockref_layer
|
||||
def get_insert_color_layer(lib_doc, blockname):
|
||||
msp_lib = lib_doc.modelspace()
|
||||
color = 0
|
||||
layer = 0
|
||||
for insert in msp_lib.query("INSERT"):
|
||||
if insert.dxf.name == blockname:
|
||||
color = insert.dxf.color
|
||||
layer = insert.dxf.layer
|
||||
return layer, color
|
||||
|
||||
|
||||
def normalize_func_name(name):
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user