Skip to content

Feature Request: LTSpice ASC File Export #82

@ksugahar

Description

@ksugahar

Summary

Add the ability to export SchemDraw circuits to LTSpice ASC format, enabling a seamless workflow from documentation to simulation.

Motivation

SchemDraw creates beautiful publication-quality circuit diagrams. However, users often need to simulate these circuits as well. Currently, this requires manually recreating the circuit in LTSpice, which is:

  1. Time-consuming - Redrawing the same circuit twice
  2. Error-prone - Manual transcription can introduce mistakes
  3. Maintenance burden - Changes must be made in two places

An ASC export feature would allow users to:

  • Design circuits once in Python
  • Generate both documentation (PDF/SVG) and simulation files (ASC)
  • Maintain a single source of truth for circuit designs

Proof of Concept

I have developed a working prototype that demonstrates this is feasible.

Supported Components

  • Resistors, Inductors, Capacitors
  • Current sources, Voltage sources
  • Wires and ground symbols
  • Labels and output flags
  • SPICE directives (.ac, .tran, etc.)

Example Usage

with schemdraw.Drawing() as d:
    I1 = d.add(elm.SourceI().up().label('I1\nAC 1'))
    R1 = d.add(elm.Resistor().right().label('R1\n1k'))
    d.add(elm.Dot())
    C1 = d.add(elm.Capacitor().down().label('C1\n1u'))
    d.add(elm.Line().left().to(I1.start))
    d.add(elm.Ground())

    d.save('rc_filter.pdf')
    # Proposed: d.save('rc_filter.asc')  # LTSpice format

Key Technical Challenges Solved

  1. Coordinate transformation: SchemDraw uses floating-point coordinates with Y increasing upward; LTSpice uses integer grid coordinates with Y increasing downward.

  2. Symbol anchor points: LTSpice symbols have complex anchor point rules that differ by component type and rotation.

  3. Wire routing: Automatic wire generation to connect component terminals.

Proposed Implementation

Add asc as a supported format in Drawing.save():

d.save('circuit.asc')  # Auto-detect from extension

Or as a separate module:

from schemdraw.backends import ltspice
ltspice.save(d, 'circuit.asc')

Questions

  1. Would this feature be appropriate for the core SchemDraw package, or better as a separate extension?
  2. Are there preferred patterns for adding export backends?
  3. Would you be interested in reviewing a pull request for this feature?

I'm happy to share my proof-of-concept code or submit a PR if there's interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions