I am doing automation of LTSpice using PyLTSpice library in Python.

I need to know the types of the components in the netlist or in the raw file.

  • How can I know programmatically that R1 corresponds to a resistor, and that C1 is a capacitor?

  • And how does the LTSpice solver "knows"?

The netlist is built as follow (simple example):

* C:path_to_folder\example\example.asc
R1 voltage N001 1e3
V1 N001 0 PULSE(0 5 0.1 0.1 0.1 0.1 0.5 1)
C1 voltage 0 10e-6
.tran 1

and the raw file looks like this:

Title: * C:path_to_folder\example\example.asc
Date: Mon Jun 05 10:34:20 2023
Plotname: Transient Analysis
Flags: real forward
No. Variables: 6
No. Points:           69
Offset:   0.0000000000000000e+000
Command: Linear Technology Corporation LTspice XVII
    0   time    time
    1   V(voltage)  voltage
    2   V(n001) voltage
    3   I(C1)   device_current
    4   I(R1)   device_current
    5   I(V1)   device_current
              馚香香㾹          飸荌뵹뾹떲㣁㝵㳠໳㘷໳똷໳똷顖泿㾹㦾 ...

1 Answer 1


It knows that R1 is a resistor because it starts with an R.
It knows that C1 is a capacitor because it starts with a C.

This is integral to how SPICE works; what type of component something is is fully decided by what the first letter of the component name is, and that in turn determines how the subsequent parameters are interpreted. R for resistor, C for capacitor, D for diode, X for subcircuit, and so on.

You can find a complete listing in the manual. (§LTspice®>Circuit Elements. See also §LTspice®>Introduction>General Structure and Conventions and generally everything under §LTspice®.)

  • \$\begingroup\$ You mean that if I add a resistor in the schematics and I name it Cx, it will behave as a capacitor? \$\endgroup\$ Jun 8 at 14:53
  • 2
    \$\begingroup\$ @RémiBaudoux Yes, but I would argue that you're adding a capacitor if you do that. The netlist has no concept of something being a resistor other than "the first character of the line is R", so if you change the first character to C, it won't be a resistor anymore. \$\endgroup\$
    – Hearth
    Jun 8 at 14:54
  • 2
    \$\begingroup\$ @RémiBaudoux Yes, the LTspice schematic capture program does that to allow you to name things whatever you want, but as you asked about the solver, I answered based on that. You can just skip the schematic capture entirely and simply write a netlist manually if you want, that's allowed. \$\endgroup\$
    – Hearth
    Jun 8 at 15:00
  • 1
    \$\begingroup\$ yes, that was the core of my question indeed, thanks for the answer, just that I did not expect the compiler to rename things in the background. Thank you very much! \$\endgroup\$ Jun 8 at 15:20
  • 3
    \$\begingroup\$ @RémiBaudoux You can override that by ctrl-right-clicking on the element and changing the "prefix" field. I do that a lot to use the built-in MOSFET symbols with subcircuit models (which need the X prefix), for instance. \$\endgroup\$
    – Hearth
    Jun 8 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.