Multiline directives


Hi. Just wondering. How to make multi-line directives?

Manual say. +/-pspice or +/-gnucap.

But it isn’t work. Not inclined those lines in netlist.

Also checked soursecode. Look like. its no code for that. Also it have code for + to include custom directives. But code also have it set by default to false. And it no options to change that.

Trying to make coupled inductor. And it easier to use directives. Creating .lib not so flexible.

e.g . K1 L1 L2 1

// Flag to follow multiline directives
bool directiveStarted = false;

else if( line.StartsWith( ‘.’ ) // one-line directives
|| controlBlock // .control … .endc block
|| ( directiveStarted && line.StartsWith( ‘+’ ) ) ) // multiline directives

This mean it will newer include directives to netlist.

 || ( directiveStarted && line.StartsWith( '+' ) ) ) // multiline directives


The ‘+’ sign at the front of an input line for ngspice is indicating that the line following after the ‘+’ is a continuation of the previous line.

This has been used in the past when a console output did show no more than 80 characters. So one used to cut a longer line into pieces, all smaller than 80 characters. Today it may be used for better readability, but is not really required.

Just make the previous line as long as you wish, instead of cutting it into pieces.

I do not see why in your example ‘K1 L1 L2 1’ you need a very long input line.


Than I misunderstood code.
I need to include statement in netlist for coupled inductor. Something like Kxxx L1 L2 L3 1. But didn’t find way to do it.

Manual say just put text box start with +spice and all text after will be included. But it doesn’t work.

Thank you.


The chapter entitled ‘Create a Netlist’ is probably not up-to-date, at least it was written for generating an off-line spice netlist to be loaded into a stand-alone simulator.

For ngspice integrated into Eeschema a chapter ‘Simulator’ has been added to the bottom of the manual.

After you have entered your circuit into the main Eeschema window, and you want to start a simulation, you may enter the simulation command e.g. for transient simulation either by Tools->Simulator->Settings->Transient, or you add a text window near to the circuit drawing with ‘.tran 1u 10m’. You may edit this text window by double clicking. A text editor window pops up. Then you may add a second line following the .tran line. It may contain ‘Kxxx L1 L2 L3 1’, so the text box will read
.tran 1u 10m
Kxxx L1 L2 L3 1
Both lines become part of the internal netlist sent to ngspice.


Thank you for reply.
Had tried it multiple time. Doesnt work. Simulation wont start. It say please define sim setting before starting.

After remove K1 L1 L2 1 from custom parameters - everything work fine, except it no coupled inductors.

here my circuit. May be I’m doing something wrong?

noname.sch (3.1 KB)


I have trouble to use multi-line directly in new KiCad 5.x version, where I did not have problem with 4.x version… I also looking for solution on this issue…


It does work if you do what I have suggested above.

Currently you have two different text boxes in your drawing. That is wrong.

Delete the text box containing the ‘L1 …’.
Double click onto the text box containing ‘.tran …’.
A editor text box with the header ‘Text Properties’ opens.
Add a line underneath the line ‘.tran …’ with the contents ‘K1 L1 L2 1’. Store by ‘ok’. Now you have two lines in the text box:

.tran 1n 1000n
K1 L1 L2 1

Then start the simulator. What you see is: constant voltages everywhere. You have coils, and you need an ac voltage. For transient simulation, double click onto ‘dc 5 ac 0’ on the voltage source and add a sine wave ‘dc 5 ac 0 sin 0 1 10Meg’. If you then run the simulator, you will see v(a), v(b) as sine waves as well.


Thank you for your help. But it not work in my eeschema. Maybe it some kind of bug. I have (5.0.1)-1 release build.

Here is circuit. Did exactly how you said.
But it not include K1 L1 L2 1 to netlist :confused:

noname.sch (3.3 KB)


Attached you will find your file from yesterday, modified and o.k with my Eeschema (5.0.0, version info see below). This file differs from your today’s file (text compare) only in that your file resorts to some rescue libraries that I do not have.

malc100208.sch (3.1 KB)

Application: eeschema
Version: (5.0.0), release build
    wxWidgets 3.0.3
    libcurl/7.54.1 OpenSSL/1.0.2l zlib/1.2.11 libssh2/1.8.0 nghttp2/1.23.1 librtmp/2.3
Platform: Windows 7 (build 7601, Service Pack 1), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
    wxWidgets: 3.0.3 (wchar_t,wx containers,compatible with 2.8)
    Boost: 1.60.0
    OpenCASCADE Community Edition: 6.8.0
    Curl: 7.54.1
    Compiler: GCC 7.1.0 with C++ ABI 1011

Build settings:


I just upgraded to KiCad 5.0.2:

And you are right! No ‘K1 L1 L2 1’ in the netlist.

The corresponding line in file malc190208.sch reads

.tran 1n 1000n\nK1 L1 L2 1\n

and thus seems to be o.k.

A bug? A new ‘feature’? I will have to play around a little bit.

Application: eeschema
Version: (5.0.2)-1, release build
    wxWidgets 3.0.4
    libcurl/7.61.1 OpenSSL/1.1.1 (WinSSL) zlib/1.2.11 brotli/1.0.6 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) nghttp2/1.34.0
Platform: Windows 7 (build 7601, Service Pack 1), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8)
    Boost: 1.68.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.61.1
    Compiler: GCC 8.2.0 with C++ ABI 1013

Build settings:


Cross checked with a 5.0.0 installation on another machine: 5.0.2 does not work here.

This seems to be a severe bug, that definitely hampers ngspice usage. I will file a bug report.


Well, it is a medium severe bug, because it concerns only the lines with coupling constants.

K1 L1 L2 1

will not be entered into the netlist, all others (dot commands or .control … .endc sections) will be copied from the text box into the netlist.

As a workaround you have to use a .lib file with an inductor subcircuit.

A bug report is filed (

You may enter a ‘me too’ to this report.


Could you check if current nightly is also affected? Would be good to know as the 5.1 release is planned to be released shortly. (I would guess that such a regression would get a high priority.)

  • This program source code file is part of KiCad, a free EDA CAD application.
  • Copyright © 1992-2013 jp.charras at
  • Copyright © 2013 SoftPLC Corporation, Dick Hollenbeck
  • Copyright © 1992-2019 KiCad Developers, see AUTHORS.TXT for contributors.
  • This program is free software; you can redistribute it and/or
  • modify it under the terms of the GNU General Public License
  • as published by the Free Software Foundation; either version 2
  • of the License, or (at your option) any later version.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License
  • along with this program; if not, you may find one here:
  • or you may search the website for the version 2 license,
  • or you may write to the Free Software Foundation, Inc.,
  • 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

#include “netlist_exporter_pspice.h”
#include <fctsys.h>
#include <build_version.h>
#include <confirm.h>

#include <search_stack.h>

#include <sch_edit_frame.h>
#include <netlist.h>
#include <sch_reference_list.h>
#include <env_paths.h>

#include <wx/tokenzr.h>
#include <wx/regex.h>


Start here \//
// Analyze each line of a text field
wxStringTokenizer tokenizer( text, “\r\n” );

        // Flag to follow multiline directives
        bool directiveStarted = false;

        while( tokenizer.HasMoreTokens() )
            wxString line( tokenizer.GetNextToken() );

            // Cleanup: remove preceding and trailing white-space characters
            line.Trim( true ).Trim( false );
            // Convert to lower-case for parsing purposes only
            wxString lowercaseline = line;

            // 'Include' directive stores the library file name, so it
            // can be later resolved using a list of paths
            if( lowercaseline.StartsWith( ".inc" ) )
                wxString lib = line.AfterFirst( ' ' );

                if( lib.IsEmpty() )

                // Strip quotes if present
                if( ( lib.StartsWith( "\"" ) && lib.EndsWith( "\"" ) )
                    || ( lib.StartsWith( "'" ) && lib.EndsWith( "'" ) ) )
                    lib = lib.Mid( 1, lib.Length() - 2 );

                m_libraries.insert( lib );

            // Store the title to be sure it appears
            // in the first line of output
            else if( lowercaseline.StartsWith( ".title " ) )
                m_title = line.AfterFirst( ' ' );

            // Handle .control .. .endc blocks
            else if( lowercaseline.IsSameAs( ".control" ) && ( !controlBlock ) )
                controlBlock = true;
                m_directives.push_back( line );
            else if( lowercaseline.IsSameAs( ".endc" ) && controlBlock )
                controlBlock = false;
                m_directives.push_back( line );

            else if( line.StartsWith( '.' )                           // one-line directives
                    || controlBlock                                   // .control .. .endc block
                    || ( directiveStarted && line.StartsWith( '+' ) ) ) // multiline directives
                m_directives.push_back( line );

            // Mark directive as started or continued in case it is a multi-line one
            directiveStarted = line.StartsWith( '.' )
                || ( directiveStarted && line.StartsWith( '+' ) );


void NETLIST_EXPORTER_PSPICE::writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const
for( auto& dir : m_directives )
aFormatter->Print( 0, “%s\n”, (const char*) dir.c_str() );

// Entries in the vector below have to follow the order in SPICE_FIELD enum
const std::vector NETLIST_EXPORTER_PSPICE::m_spiceFields = {

Checked sourcecode its no line in code for export KXXX.
Only thing it have - include librarys, but it work fine from component properties. and ‘.’ directives. But ngspise doesn’t understand '.Kxxxx ’ it wont starting simulation with that.

Sorry for long post. Don`t know how to make spoiler here.


Same with current nightly.



Seth has uploaded a fix.


Well I also have couple other bug report for pspice relative mater, so I will listed here for just reference since this issue isn’t new, but developer think they fix it:


For me it is difficult to understand what you try to achieve.

There are two ways running a simulation in KiCad:

  • Use the integrated ngspice
  • Generate a netlist and simulate externally with whatever simulator (e.g. PSPICE).

**Set current directory to project before run custom simulator
What do you mean by: “ngspice tool do not understand windows system absolute file path that automatically send by KiCad” ? Could you give an example?

** simulation: TEMP sweep not able to plot anything
You are using eeschema/ngspice in a way that has not been intended by the devs and that is not supported. KiCad sends the netlist, .tran etc. command and a ‘run’ command to ngspice and gets back all simulation results for plotting. Your setup generates its own simulation command and issues a request for plotting, both from inside of ngspice. Whereas running the simulation this way is possible, it is not possible to plot the data, because shared ngspice does not have its own plot interface, and eeschema does not know about the data generated by ngspice. So you only might save the data by ‘write’ command and use an external plotting program (e.g. stand-alone ngspice).

**Can’t start a multi-line SPICE directive with a commented-out line
Did you check with a recent nightly if this has been fixed? If not, I could have a look.

** ngspice use net name “0” (Zero) as a reference ground not GND
This is wrong. ngspice always understood GND. Internally it will be transformed into ‘0’. ‘0’ is required somewhere as a reference. If you do not want this automated translation, you may give the command ‘set no_auto_gnd’. Then you have to provide your own ‘0’ somewhere in the netlist.

If you intend to generate a netlist compatible with an external other simulator, you have to state that clearly in your bug report. And then the devs have to decide if this should be supported.


This is the issue when I try to run simulate externally… ngspice seem to not able to run my netlist file, and it very hard to run under interactive mode when I have to type so much for the “absolute” path. When I start Kicad under my current netlist folder, everything run automatically and avoid type so much for absolute path. But if I start KiCad form the Windows -> Start menu it just not working with absolute path.


In this case, I don’t have problem with run “external” method. But I just to to let developer know it not support for “integrated” mode.