296 lines
8.7 KiB
Python
296 lines
8.7 KiB
Python
import ezdxf
|
|
from ezdxf import colors
|
|
from ezdxf.enums import TextEntityAlignment
|
|
import math
|
|
|
|
def create_grounding_symbol(filename="erdung.dxf"):
|
|
"""Erstellt ein Schutzerde-Symbol nach DIN EN 60617"""
|
|
doc = ezdxf.new('R2010')
|
|
msp = doc.modelspace()
|
|
|
|
# Block erstellen
|
|
block = doc.blocks.new(name='ERDUNG')
|
|
|
|
# Mittelpunkt (relativ zum Block)
|
|
cx, cy = 0, 0
|
|
|
|
# Vertikale Linie (Erdungsleiter)
|
|
block.add_line((cx, cy + 60), (cx, cy - 20))
|
|
|
|
# Drei horizontale Linien (Erdsymbol)
|
|
# Obere Linie (längste)
|
|
block.add_line((cx - 40, cy - 20), (cx + 40, cy - 20))
|
|
# Mittlere Linie
|
|
block.add_line((cx - 25, cy - 35), (cx + 25, cy - 35))
|
|
# Untere Linie (kürzeste)
|
|
block.add_line((cx - 15, cy - 50), (cx + 15, cy - 50))
|
|
|
|
# Beschriftung PE
|
|
block.add_text("PE", dxfattribs={
|
|
'height': 12,
|
|
'insert': (cx, cy + 70),
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
# Attribute definieren
|
|
block.add_attdef(tag='REALE_POSITION', insert=(cx, cy - 70), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Reale Position:',
|
|
'default': 'x',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1 # Unsichtbar, nur für Daten
|
|
})
|
|
|
|
block.add_attdef(tag='NAME', insert=(cx, cy - 85), dxfattribs={
|
|
'height': 10,
|
|
'prompt': 'Name:',
|
|
'default': '',
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
block.add_attdef(tag='KENNZEICHNUNG', insert=(cx, cy - 100), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Kennzeichnung:',
|
|
'default': '=A01+UH00-X01',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1 # Unsichtbar, nur für Daten
|
|
})
|
|
|
|
# Block-Instanz einfügen
|
|
msp.add_blockref('ERDUNG', (125, 125))
|
|
|
|
doc.saveas(filename)
|
|
print(f"✓ {filename} erstellt")
|
|
|
|
def create_switchboard_symbol(filename="schaltschrank.dxf"):
|
|
"""Erstellt ein schematisches Schaltschrank-Symbol für Lagepläne"""
|
|
doc = ezdxf.new('R2010')
|
|
msp = doc.modelspace()
|
|
|
|
# Block erstellen
|
|
block = doc.blocks.new(name='SCHALTSCHRANK')
|
|
|
|
# Mittelpunkt (relativ zum Block)
|
|
cx, cy = 0, 0
|
|
|
|
# Rechteck für Schaltschrank (60x80mm)
|
|
width, height = 60, 80
|
|
x1, y1 = cx - width/2, cy - height/2
|
|
x2, y2 = cx + width/2, cy + height/2
|
|
|
|
# Außenrahmen
|
|
block.add_lwpolyline([
|
|
(x1, y1), (x2, y1), (x2, y2), (x1, y2), (x1, y1)
|
|
], dxfattribs={'closed': True})
|
|
|
|
# Innere Unterteilung (Fächer)
|
|
block.add_line((x1, cy - 15), (x2, cy - 15))
|
|
block.add_line((x1, cy + 15), (x2, cy + 15))
|
|
|
|
# Türgriff-Symbol (vertikale Linie links)
|
|
block.add_line((x1 + 5, cy - 25), (x1 + 5, cy + 25))
|
|
|
|
# Beschriftung
|
|
block.add_text("Schaltschrank", dxfattribs={
|
|
'height': 10,
|
|
'insert': (cx, y2 + 15),
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
# Attribute definieren
|
|
block.add_attdef(tag='REALE_POSITION', insert=(cx, y1 - 15), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Reale Position:',
|
|
'default': 'x',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
block.add_attdef(tag='NAME', insert=(cx, y1 - 30), dxfattribs={
|
|
'height': 10,
|
|
'prompt': 'Name:',
|
|
'default': '',
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
block.add_attdef(tag='KENNZEICHNUNG', insert=(cx, y1 - 45), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Kennzeichnung:',
|
|
'default': '=A01+UH00-X01',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
# Block-Instanz einfügen
|
|
msp.add_blockref('SCHALTSCHRANK', (125, 125))
|
|
|
|
doc.saveas(filename)
|
|
print(f"✓ {filename} erstellt")
|
|
|
|
def create_subdistribution_symbol(filename="unterverteiler.dxf"):
|
|
"""Erstellt ein Unterverteiler-Symbol (ähnlich Schaltschrank, kleiner)"""
|
|
doc = ezdxf.new('R2010')
|
|
msp = doc.modelspace()
|
|
|
|
# Block erstellen
|
|
block = doc.blocks.new(name='UNTERVERTEILER')
|
|
|
|
# Mittelpunkt (relativ zum Block)
|
|
cx, cy = 0, 0
|
|
|
|
# Rechteck für Unterverteiler (45x60mm - kleiner als Schaltschrank)
|
|
width, height = 45, 60
|
|
x1, y1 = cx - width/2, cy - height/2
|
|
x2, y2 = cx + width/2, cy + height/2
|
|
|
|
# Außenrahmen
|
|
block.add_lwpolyline([
|
|
(x1, y1), (x2, y1), (x2, y2), (x1, y2), (x1, y1)
|
|
], dxfattribs={'closed': True})
|
|
|
|
# Innere Unterteilung (weniger Fächer)
|
|
block.add_line((x1, cy), (x2, cy))
|
|
|
|
# Türgriff-Symbol
|
|
block.add_line((x1 + 4, cy - 15), (x1 + 4, cy + 15))
|
|
|
|
# Beschriftung UV (Unterverteiler)
|
|
block.add_text("UV", dxfattribs={
|
|
'height': 12,
|
|
'insert': (cx, cy),
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'valign': TextEntityAlignment.MIDDLE
|
|
})
|
|
|
|
# Zusätzliche Beschriftung
|
|
block.add_text("Unterverteiler", dxfattribs={
|
|
'height': 10,
|
|
'insert': (cx, y2 + 15),
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
# Attribute definieren
|
|
block.add_attdef(tag='REALE_POSITION', insert=(cx, y1 - 15), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Reale Position:',
|
|
'default': 'x',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
block.add_attdef(tag='NAME', insert=(cx, y1 - 30), dxfattribs={
|
|
'height': 10,
|
|
'prompt': 'Name:',
|
|
'default': '',
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
block.add_attdef(tag='KENNZEICHNUNG', insert=(cx, y1 - 45), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Kennzeichnung:',
|
|
'default': '=A01+UH00-X01',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
# Block-Instanz einfügen
|
|
msp.add_blockref('UNTERVERTEILER', (125, 125))
|
|
|
|
doc.saveas(filename)
|
|
print(f"✓ {filename} erstellt")
|
|
|
|
def create_motor_symbol(filename="motor.dxf"):
|
|
"""Erstellt ein allgemeines Motor-Symbol (M im Kreis) nach DIN EN 60617"""
|
|
doc = ezdxf.new('R2010')
|
|
msp = doc.modelspace()
|
|
|
|
# Block erstellen
|
|
block = doc.blocks.new(name='MOTOR')
|
|
|
|
# Mittelpunkt (relativ zum Block)
|
|
cx, cy = 0, 0
|
|
radius = 30
|
|
|
|
# Kreis
|
|
block.add_circle((cx, cy), radius)
|
|
|
|
# Buchstabe "M" in der Mitte
|
|
block.add_text("M", dxfattribs={
|
|
'height': 25,
|
|
'insert': (cx, cy),
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'valign': TextEntityAlignment.MIDDLE
|
|
})
|
|
|
|
# Anschlussklemmen (drei Linien für Drehstrom - optional)
|
|
# Oben
|
|
block.add_line((cx, cy + radius), (cx, cy + radius + 20))
|
|
# Links unten
|
|
angle1 = math.radians(210)
|
|
x1 = cx + radius * math.cos(angle1)
|
|
y1 = cy + radius * math.sin(angle1)
|
|
block.add_line((x1, y1), (x1 - 15, y1 - 10))
|
|
# Rechts unten
|
|
angle2 = math.radians(330)
|
|
x2 = cx + radius * math.cos(angle2)
|
|
y2 = cy + radius * math.sin(angle2)
|
|
block.add_line((x2, y2), (x2 + 15, y2 - 10))
|
|
|
|
# Beschriftung
|
|
block.add_text("Motor", dxfattribs={
|
|
'height': 10,
|
|
'insert': (cx, cy - radius - 25),
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
# Attribute definieren
|
|
block.add_attdef(tag='REALE_POSITION', insert=(cx, cy - radius - 40), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Reale Position:',
|
|
'default': 'x',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
block.add_attdef(tag='NAME', insert=(cx, cy - radius - 55), dxfattribs={
|
|
'height': 10,
|
|
'prompt': 'Name:',
|
|
'default': '',
|
|
'halign': TextEntityAlignment.CENTER
|
|
})
|
|
|
|
block.add_attdef(tag='KENNZEICHNUNG', insert=(cx, cy - radius - 70), dxfattribs={
|
|
'height': 8,
|
|
'prompt': 'Kennzeichnung:',
|
|
'default': '=A01+UH00-X01',
|
|
'halign': TextEntityAlignment.CENTER,
|
|
'invisible': 1
|
|
})
|
|
|
|
# Block-Instanz einfügen
|
|
msp.add_blockref('MOTOR', (125, 125))
|
|
|
|
doc.saveas(filename)
|
|
print(f"✓ {filename} erstellt")
|
|
|
|
# Hauptprogramm
|
|
if __name__ == "__main__":
|
|
print("Erstelle DXF Elektrosymbole nach DIN EN 60617 mit Attributen...\n")
|
|
|
|
create_grounding_symbol()
|
|
create_switchboard_symbol()
|
|
create_subdistribution_symbol()
|
|
create_motor_symbol()
|
|
|
|
print("\n✓ Alle Symbole wurden erfolgreich erstellt!")
|
|
print("\nDateien:")
|
|
print(" - erdung.dxf")
|
|
print(" - schaltschrank.dxf")
|
|
print(" - unterverteiler.dxf")
|
|
print(" - motor.dxf")
|
|
print("\nJedes Symbol ist als Block mit folgenden Attributen definiert:")
|
|
print(" - REALE_POSITION (Standard: 'x', unsichtbar)")
|
|
print(" - NAME (Standard: leer, sichtbar unter dem Symbol)")
|
|
print(" - KENNZEICHNUNG (Standard: '=A01+UH00-X01', unsichtbar)")
|
|
print("\nDie Attribute können in CAD-Programmen bearbeitet werden.")
|