-
Notifications
You must be signed in to change notification settings - Fork 42
Description
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:
- Time-consuming - Redrawing the same circuit twice
- Error-prone - Manual transcription can introduce mistakes
- 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 formatKey Technical Challenges Solved
-
Coordinate transformation: SchemDraw uses floating-point coordinates with Y increasing upward; LTSpice uses integer grid coordinates with Y increasing downward.
-
Symbol anchor points: LTSpice symbols have complex anchor point rules that differ by component type and rotation.
-
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 extensionOr as a separate module:
from schemdraw.backends import ltspice
ltspice.save(d, 'circuit.asc')Questions
- Would this feature be appropriate for the core SchemDraw package, or better as a separate extension?
- Are there preferred patterns for adding export backends?
- 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.