Omniflo Boegen und Weichen auch durch .py erzeugen und ändern.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# ============================================
|
||||
|
||||
import os
|
||||
import json
|
||||
import math
|
||||
|
||||
import PyDb as Db
|
||||
@@ -12,6 +13,34 @@ import PyGe as Ge
|
||||
_letzte_nummern = {}
|
||||
|
||||
|
||||
def get_data_path():
|
||||
"""Daten-Pfad aus Umgebungsvariable DXFM_DATA lesen."""
|
||||
dp = os.environ.get("DXFM_DATA", "")
|
||||
if not dp:
|
||||
print("\nFEHLER: DXFM_DATA nicht gesetzt!")
|
||||
return None
|
||||
return dp.replace("\\", "/").rstrip("/")
|
||||
|
||||
|
||||
def load_json_data(rel_path):
|
||||
"""JSON-Datei relativ zum DXFM_DATA-Pfad laden.
|
||||
|
||||
Parameter:
|
||||
rel_path - relativer Pfad, z.B. "json/omniflo_boegen.json"
|
||||
Rueckgabe: geparste Daten oder leere Liste bei Fehler
|
||||
"""
|
||||
dp = get_data_path()
|
||||
if not dp:
|
||||
return []
|
||||
path = f"{dp}/{rel_path}"
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
print(f"\nFEHLER beim Laden von {path}: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_block_path():
|
||||
"""Block-Pfad aus Umgebungsvariable DXFM_BLOCKS lesen."""
|
||||
bp = os.environ.get("DXFM_BLOCKS", "")
|
||||
@@ -135,6 +164,28 @@ def ensure_block_from_dwg(db, dwg_name, block_path=None):
|
||||
return True
|
||||
|
||||
|
||||
def ensure_block_from_dxf(db, dxf_path, block_name=None):
|
||||
"""DXF-Datei als Block-Definition laden falls nicht vorhanden.
|
||||
|
||||
Parameter:
|
||||
db - aktuelle Datenbank
|
||||
dxf_path - absoluter Pfad zur DXF-Datei
|
||||
block_name - Name der Block-Definition (default: Dateiname ohne .dxf)
|
||||
Rueckgabe: True wenn erfolgreich, False bei Fehler
|
||||
"""
|
||||
if block_name is None:
|
||||
block_name = os.path.splitext(os.path.basename(dxf_path))[0]
|
||||
bt = Db.BlockTable(db.blockTableId(), Db.OpenMode.kForRead)
|
||||
if not bt.has(block_name):
|
||||
if not os.path.isfile(dxf_path):
|
||||
print(f"\nFehler: DXF nicht gefunden: {dxf_path}")
|
||||
return False
|
||||
aux_db = Db.Database(False, True)
|
||||
aux_db.dxfIn(dxf_path)
|
||||
db.insert(aux_db, block_name)
|
||||
return True
|
||||
|
||||
|
||||
def create_attrib_defs(btr, attrib_defs, text_height=50.0):
|
||||
"""Unsichtbare Attribut-Definitionen in einer BlockTableRecord erzeugen.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user