import uuid

def generate_kicad_uuid():
    return str(uuid.uuid4())

def create_mullard_kicad_sch(output_filename="mullard_5_10.kicad_sch"):
    # Nagłówek formatu KiCad 7/8/9
    sch_content = f"""(kicad_sch
  (version 20231120)
  (generator "Python_KiCad_Generator")
  (generator_version "1.0")
  (uuid "{generate_kicad_uuid()}")
  (paper "A4")
  (title_block
    (title "Wzmacniacz Lampowy Mullard 5-10")
    (company "DIY Audio")
    (rev "1.0")
  )
"""

    # Słownik elementów: [symbol, ref, val, x, y]
    components = [
        # Lampy
        {"sym": "Valve:EF86", "ref": "V1", "val": "EF86", "x": 50, "y": 80},
        {"sym": "Valve:ECC83", "ref": "V2", "val": "ECC83", "x": 100, "y": 80},
        {"sym": "Valve:EL84", "ref": "V3", "val": "EL84", "x": 160, "y": 60},
        {"sym": "Valve:EL84", "ref": "V4", "val": "EL84", "x": 160, "y": 110},
        {"sym": "Valve:EZ81", "ref": "V5", "val": "EZ81", "x": 220, "y": 80},

        # Elementy bierne - Stopień wejściowy EF86
        {"sym": "Device:R", "ref": "Ra1", "val": "100k", "x": 50, "y": 50},
        {"sym": "Device:R", "ref": "Rk1", "val": "1.5k", "x": 50, "y": 110},
        {"sym": "Device:C", "ref": "Ck1", "val": "50uF", "x": 60, "y": 110},

        # Elementy bierne - Odwracacz fazy ECC83
        {"sym": "Device:R", "ref": "Ra2", "val": "100k", "x": 95, "y": 50},
        {"sym": "Device:R", "ref": "Ra3", "val": "100k", "x": 105, "y": 50},
        {"sym": "Device:R", "ref": "Rtail", "val": "47k", "x": 100, "y": 110},

        # Elementy bierne - Stopień mocy EL84
        {"sym": "Device:R", "ref": "Rk2", "val": "270R 3W", "x": 160, "y": 140},
        {"sym": "Device:C", "ref": "Ck2", "val": "50uF", "x": 170, "y": 140},
        {"sym": "Device:C", "ref": "C1", "val": "47nF 400V", "x": 130, "y": 60},
        {"sym": "Device:C", "ref": "C2", "val": "47nF 400V", "x": 130, "y": 110},
    ]

    # Generowanie instancji symboli
    for comp in components:
        comp_uuid = generate_kicad_uuid()
        sch_content += f"""
  (symbol
    (lib_id "{comp['sym']}")
    (at {comp['x']} {comp['y']} 0)
    (unit 1)
    (exclude_from_sim no)
    (in_bom yes)
    (on_board yes)
    (dnp no)
    (uuid "{comp_uuid}")
    (property "Reference" "{comp['ref']}"
      (at {comp['x']} {comp['y'] - 5} 0)
      (effects (font (size 1.27 1.27)))
    )
    (property "Value" "{comp['val']}"
      (at {comp['x']} {comp['y'] + 5} 0)
      (effects (font (size 1.27 1.27)))
    )
  )"""

    # Etykiety zasilania i masy (Power/Global Labels)
    labels = [
        {"name": "+300V_B1", "x": 220, "y": 40},
        {"name": "+275V_B2", "x": 160, "y": 40},
        {"name": "+200V_B3", "x": 50, "y": 40},
        {"name": "GND", "x": 100, "y": 160},
    ]

    for lbl in labels:
        lbl_uuid = generate_kicad_uuid()
        sch_content += f"""
  (global_label "{lbl['name']}"
    (shape input)
    (at {lbl['x']} {lbl['y']} 0)
    (fields_autoplaced yes)
    (uuid "{lbl_uuid}")
    (effects (font (size 1.27 1.27)) (justify left))
  )"""

    sch_content += "\n)\n"

    # Zapis do pliku
    with open(output_filename, "w", encoding="utf-8") as f:
        f.write(sch_content)

    print(f"Pomyślnie wygenerowano plik schematu: {output_filename}")

if __name__ == "__main__":
    create_mullard_kicad_sch()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: