Creating Customized Netlists and BOM Files

Intermediate Netlist File

BOM files and netlist files can be converted from an Intermediate netlist file created by Eeschema.

This file uses XML syntax and is called the intermediate netlist. The intermediate netlist includes a large amount of data about your board and because of this, it can be used with post-processing to create a BOM or other reports.

Depending on the output (BOM or netlist), different subsets of the complete Intermediate Netlist file will be used in the post-processing.

Schematic sample

Schematic sample

The Intermediate Netlist file sample

The corresponding intermediate netlist (using XML syntax) of the circuit above is shown below.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <export version="D">
  3. <design>
  4. <source>F:\kicad_aux\netlist_test\netlist_test.sch</source>
  5. <date>29/08/2010 20:35:21</date>
  6. <tool>eeschema (2010-08-28 BZR 2458)-unstable</tool>
  7. </design>
  8. <components>
  9. <comp ref="P1">
  10. <value>CONN_4</value>
  11. <libsource lib="conn" part="CONN_4"/>
  12. <sheetpath names="/" tstamps="/"/>
  13. <tstamp>4C6E2141</tstamp>
  14. </comp>
  15. <comp ref="U2">
  16. <value>74LS74</value>
  17. <libsource lib="74xx" part="74LS74"/>
  18. <sheetpath names="/" tstamps="/"/>
  19. <tstamp>4C6E20BA</tstamp>
  20. </comp>
  21. <comp ref="U1">
  22. <value>74LS04</value>
  23. <libsource lib="74xx" part="74LS04"/>
  24. <sheetpath names="/" tstamps="/"/>
  25. <tstamp>4C6E20A6</tstamp>
  26. </comp>
  27. <comp ref="C1">
  28. <value>CP</value>
  29. <libsource lib="device" part="CP"/>
  30. <sheetpath names="/" tstamps="/"/>
  31. <tstamp>4C6E2094</tstamp>
  32. </comp>
  33. <comp ref="R1">
  34. <value>R</value>
  35. <libsource lib="device" part="R"/>
  36. <sheetpath names="/" tstamps="/"/>
  37. <tstamp>4C6E208A</tstamp>
  38. </comp>
  39. </components>
  40. <libparts>
  41. <libpart lib="device" part="C">
  42. <description>Condensateur non polarise</description>
  43. <footprints>
  44. <fp>SM*</fp>
  45. <fp>C?</fp>
  46. <fp>C1-1</fp>
  47. </footprints>
  48. <fields>
  49. <field name="Reference">C</field>
  50. <field name="Value">C</field>
  51. </fields>
  52. <pins>
  53. <pin num="1" name="~" type="passive"/>
  54. <pin num="2" name="~" type="passive"/>
  55. </pins>
  56. </libpart>
  57. <libpart lib="device" part="R">
  58. <description>Resistance</description>
  59. <footprints>
  60. <fp>R?</fp>
  61. <fp>SM0603</fp>
  62. <fp>SM0805</fp>
  63. <fp>R?-*</fp>
  64. <fp>SM1206</fp>
  65. </footprints>
  66. <fields>
  67. <field name="Reference">R</field>
  68. <field name="Value">R</field>
  69. </fields>
  70. <pins>
  71. <pin num="1" name="~" type="passive"/>
  72. <pin num="2" name="~" type="passive"/>
  73. </pins>
  74. </libpart>
  75. <libpart lib="conn" part="CONN_4">
  76. <description>Symbole general de connecteur</description>
  77. <fields>
  78. <field name="Reference">P</field>
  79. <field name="Value">CONN_4</field>
  80. </fields>
  81. <pins>
  82. <pin num="1" name="P1" type="passive"/>
  83. <pin num="2" name="P2" type="passive"/>
  84. <pin num="3" name="P3" type="passive"/>
  85. <pin num="4" name="P4" type="passive"/>
  86. </pins>
  87. </libpart>
  88. <libpart lib="74xx" part="74LS04">
  89. <description>Hex Inverseur</description>
  90. <fields>
  91. <field name="Reference">U</field>
  92. <field name="Value">74LS04</field>
  93. </fields>
  94. <pins>
  95. <pin num="1" name="~" type="input"/>
  96. <pin num="2" name="~" type="output"/>
  97. <pin num="3" name="~" type="input"/>
  98. <pin num="4" name="~" type="output"/>
  99. <pin num="5" name="~" type="input"/>
  100. <pin num="6" name="~" type="output"/>
  101. <pin num="7" name="GND" type="power_in"/>
  102. <pin num="8" name="~" type="output"/>
  103. <pin num="9" name="~" type="input"/>
  104. <pin num="10" name="~" type="output"/>
  105. <pin num="11" name="~" type="input"/>
  106. <pin num="12" name="~" type="output"/>
  107. <pin num="13" name="~" type="input"/>
  108. <pin num="14" name="VCC" type="power_in"/>
  109. </pins>
  110. </libpart>
  111. <libpart lib="74xx" part="74LS74">
  112. <description>Dual D FlipFlop, Set &amp; Reset</description>
  113. <docs>74xx/74hc_hct74.pdf</docs>
  114. <fields>
  115. <field name="Reference">U</field>
  116. <field name="Value">74LS74</field>
  117. </fields>
  118. <pins>
  119. <pin num="1" name="Cd" type="input"/>
  120. <pin num="2" name="D" type="input"/>
  121. <pin num="3" name="Cp" type="input"/>
  122. <pin num="4" name="Sd" type="input"/>
  123. <pin num="5" name="Q" type="output"/>
  124. <pin num="6" name="~Q" type="output"/>
  125. <pin num="7" name="GND" type="power_in"/>
  126. <pin num="8" name="~Q" type="output"/>
  127. <pin num="9" name="Q" type="output"/>
  128. <pin num="10" name="Sd" type="input"/>
  129. <pin num="11" name="Cp" type="input"/>
  130. <pin num="12" name="D" type="input"/>
  131. <pin num="13" name="Cd" type="input"/>
  132. <pin num="14" name="VCC" type="power_in"/>
  133. </pins>
  134. </libpart>
  135. </libparts>
  136. <libraries>
  137. <library logical="device">
  138. <uri>F:\kicad\share\library\device.lib</uri>
  139. </library>
  140. <library logical="conn">
  141. <uri>F:\kicad\share\library\conn.lib</uri>
  142. </library>
  143. <library logical="74xx">
  144. <uri>F:\kicad\share\library\74xx.lib</uri>
  145. </library>
  146. </libraries>
  147. <nets>
  148. <net code="1" name="GND">
  149. <node ref="U1" pin="7"/>
  150. <node ref="C1" pin="2"/>
  151. <node ref="U2" pin="7"/>
  152. <node ref="P1" pin="4"/>
  153. </net>
  154. <net code="2" name="VCC">
  155. <node ref="R1" pin="1"/>
  156. <node ref="U1" pin="14"/>
  157. <node ref="U2" pin="4"/>
  158. <node ref="U2" pin="1"/>
  159. <node ref="U2" pin="14"/>
  160. <node ref="P1" pin="1"/>
  161. </net>
  162. <net code="3" name="">
  163. <node ref="U2" pin="6"/>
  164. </net>
  165. <net code="4" name="">
  166. <node ref="U1" pin="2"/>
  167. <node ref="U2" pin="3"/>
  168. </net>
  169. <net code="5" name="/SIG_OUT">
  170. <node ref="P1" pin="2"/>
  171. <node ref="U2" pin="5"/>
  172. <node ref="U2" pin="2"/>
  173. </net>
  174. <net code="6" name="/CLOCK_IN">
  175. <node ref="R1" pin="2"/>
  176. <node ref="C1" pin="1"/>
  177. <node ref="U1" pin="1"/>
  178. <node ref="P1" pin="3"/>
  179. </net>
  180. </nets>
  181. </export>

Conversion to a new netlist format

By applying a post-processing filter to the Intermediate netlist file you can generate foreign netlist files as well as BOM files. Because this conversion is a text to text transformation, this post-processing filter can be written using Python, XSLT, or any other tool capable of taking XML as input.

XSLT itself is an XML language very suitable for XML transformations. There is a free program called xsltproc that you can download and install. The xsltproc program can be used to read the Intermediate XML netlist input file, apply a style-sheet to transform the input, and save the results in an output file. Use of xsltproc requires a style-sheet file using XSLT conventions. The full conversion process is handled by Eeschema, after it is configured once to run xsltproc in a specific way.

XSLT approach

The document that describes XSL Transformations (XSLT) is available here:

http://www.w3.org/TR/xslt

Create a Pads-Pcb netlist file

The pads-pcb format is comprised of two sections.

  • The footprint list.

  • The Nets list: grouping pads references by nets.

Immediately below is a style-sheet which converts the Intermediate Netlist file to a pads-pcb netlist format:

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!--XSL style sheet to Eeschema Generic Netlist Format to PADS netlist format
  3. Copyright (C) 2010, SoftPLC Corporation.
  4. GPL v2.
  5. How to use:
  6. https://lists.launchpad.net/kicad-developers/msg05157.html
  7. -->
  8. <!DOCTYPE xsl:stylesheet [
  9. <!ENTITY nl "&#xd;&#xa;"> <!--new line CR, LF -->
  10. ]>
  11. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  12. <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
  13. <xsl:template match="/export">
  14. <xsl:text>*PADS-PCB*&nl;*PART*&nl;</xsl:text>
  15. <xsl:apply-templates select="components/comp"/>
  16. <xsl:text>&nl;*NET*&nl;</xsl:text>
  17. <xsl:apply-templates select="nets/net"/>
  18. <xsl:text>*END*&nl;</xsl:text>
  19. </xsl:template>
  20. <!-- for each component -->
  21. <xsl:template match="comp">
  22. <xsl:text> </xsl:text>
  23. <xsl:value-of select="@ref"/>
  24. <xsl:text> </xsl:text>
  25. <xsl:choose>
  26. <xsl:when test = "footprint != '' ">
  27. <xsl:apply-templates select="footprint"/>
  28. </xsl:when>
  29. <xsl:otherwise>
  30. <xsl:text>unknown</xsl:text>
  31. </xsl:otherwise>
  32. </xsl:choose>
  33. <xsl:text>&nl;</xsl:text>
  34. </xsl:template>
  35. <!-- for each net -->
  36. <xsl:template match="net">
  37. <!-- nets are output only if there is more than one pin in net -->
  38. <xsl:if test="count(node)>1">
  39. <xsl:text>*SIGNAL* </xsl:text>
  40. <xsl:choose>
  41. <xsl:when test = "@name != '' ">
  42. <xsl:value-of select="@name"/>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <xsl:text>N-</xsl:text>
  46. <xsl:value-of select="@code"/>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. <xsl:text>&nl;</xsl:text>
  50. <xsl:apply-templates select="node"/>
  51. </xsl:if>
  52. </xsl:template>
  53. <!-- for each node -->
  54. <xsl:template match="node">
  55. <xsl:text> </xsl:text>
  56. <xsl:value-of select="@ref"/>
  57. <xsl:text>.</xsl:text>
  58. <xsl:value-of select="@pin"/>
  59. <xsl:text>&nl;</xsl:text>
  60. </xsl:template>
  61. </xsl:stylesheet>

And here is the pads-pcb output file after running xsltproc:

  1. *PADS-PCB*
  2. *PART*
  3. P1 unknown
  4. U2 unknown
  5. U1 unknown
  6. C1 unknown
  7. R1 unknown
  8. *NET*
  9. *SIGNAL* GND
  10. U1.7
  11. C1.2
  12. U2.7
  13. P1.4
  14. *SIGNAL* VCC
  15. R1.1
  16. U1.14
  17. U2.4
  18. U2.1
  19. U2.14
  20. P1.1
  21. *SIGNAL* N-4
  22. U1.2
  23. U2.3
  24. *SIGNAL* /SIG_OUT
  25. P1.2
  26. U2.5
  27. U2.2
  28. *SIGNAL* /CLOCK_IN
  29. R1.2
  30. C1.1
  31. U1.1
  32. P1.3
  33. *END*

The command line to make this conversion is:

  1. kicad\\bin\\xsltproc.exe -o test.net kicad\\bin\\plugins\\netlist_form_pads-pcb.xsl test.tmp

Create a Cadstar netlist file

The Cadstar format is comprised of two sections.

  • The footprint list.

  • The Nets list: grouping pads references by nets.

Here is the style-sheet file to make this specific conversion:

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!--XSL style sheet to Eeschema Generic Netlist Format to CADSTAR netlist format
  3. Copyright (C) 2010, Jean-Pierre Charras.
  4. Copyright (C) 2010, SoftPLC Corporation.
  5. GPL v2.
  6. <!DOCTYPE xsl:stylesheet [
  7. <!ENTITY nl "&#xd;&#xa;"> <!--new line CR, LF -->
  8. ]>
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  10. <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
  11. <!-- Netlist header -->
  12. <xsl:template match="/export">
  13. <xsl:text>.HEA&nl;</xsl:text>
  14. <xsl:apply-templates select="design/date"/> <!-- Generate line .TIM <time> -->
  15. <xsl:apply-templates select="design/tool"/> <!-- Generate line .APP <eeschema version> -->
  16. <xsl:apply-templates select="components/comp"/> <!-- Generate list of components -->
  17. <xsl:text>&nl;&nl;</xsl:text>
  18. <xsl:apply-templates select="nets/net"/> <!-- Generate list of nets and connections -->
  19. <xsl:text>&nl;.END&nl;</xsl:text>
  20. </xsl:template>
  21. <!-- Generate line .TIM 20/08/2010 10:45:33 -->
  22. <xsl:template match="tool">
  23. <xsl:text>.APP "</xsl:text>
  24. <xsl:apply-templates/>
  25. <xsl:text>"&nl;</xsl:text>
  26. </xsl:template>
  27. <!-- Generate line .APP "eeschema (2010-08-17 BZR 2450)-unstable" -->
  28. <xsl:template match="date">
  29. <xsl:text>.TIM </xsl:text>
  30. <xsl:apply-templates/>
  31. <xsl:text>&nl;</xsl:text>
  32. </xsl:template>
  33. <!-- for each component -->
  34. <xsl:template match="comp">
  35. <xsl:text>.ADD_COM </xsl:text>
  36. <xsl:value-of select="@ref"/>
  37. <xsl:text> </xsl:text>
  38. <xsl:choose>
  39. <xsl:when test = "value != '' ">
  40. <xsl:text>"</xsl:text> <xsl:apply-templates select="value"/> <xsl:text>"</xsl:text>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:text>""</xsl:text>
  44. </xsl:otherwise>
  45. </xsl:choose>
  46. <xsl:text>&nl;</xsl:text>
  47. </xsl:template>
  48. <!-- for each net -->
  49. <xsl:template match="net">
  50. <!-- nets are output only if there is more than one pin in net -->
  51. <xsl:if test="count(node)>1">
  52. <xsl:variable name="netname">
  53. <xsl:text>"</xsl:text>
  54. <xsl:choose>
  55. <xsl:when test = "@name != '' ">
  56. <xsl:value-of select="@name"/>
  57. </xsl:when>
  58. <xsl:otherwise>
  59. <xsl:text>N-</xsl:text>
  60. <xsl:value-of select="@code"/>
  61. </xsl:otherwise>
  62. </xsl:choose>
  63. <xsl:text>"&nl;</xsl:text>
  64. </xsl:variable>
  65. <xsl:apply-templates select="node" mode="first"/>
  66. <xsl:value-of select="$netname"/>
  67. <xsl:apply-templates select="node" mode="others"/>
  68. </xsl:if>
  69. </xsl:template>
  70. <!-- for each node -->
  71. <xsl:template match="node" mode="first">
  72. <xsl:if test="position()=1">
  73. <xsl:text>.ADD_TER </xsl:text>
  74. <xsl:value-of select="@ref"/>
  75. <xsl:text>.</xsl:text>
  76. <xsl:value-of select="@pin"/>
  77. <xsl:text> </xsl:text>
  78. </xsl:if>
  79. </xsl:template>
  80. <xsl:template match="node" mode="others">
  81. <xsl:choose>
  82. <xsl:when test='position()=1'>
  83. </xsl:when>
  84. <xsl:when test='position()=2'>
  85. <xsl:text>.TER </xsl:text>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:text> </xsl:text>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. <xsl:if test="position()>1">
  92. <xsl:value-of select="@ref"/>
  93. <xsl:text>.</xsl:text>
  94. <xsl:value-of select="@pin"/>
  95. <xsl:text>&nl;</xsl:text>
  96. </xsl:if>
  97. </xsl:template>
  98. </xsl:stylesheet>

Here is the Cadstar output file.

  1. .HEA
  2. .TIM 21/08/2010 08:12:08
  3. .APP "eeschema (2010-08-09 BZR 2439)-unstable"
  4. .ADD_COM P1 "CONN_4"
  5. .ADD_COM U2 "74LS74"
  6. .ADD_COM U1 "74LS04"
  7. .ADD_COM C1 "CP"
  8. .ADD_COM R1 "R"
  9. .ADD_TER U1.7 "GND"
  10. .TER C1.2
  11. U2.7
  12. P1.4
  13. .ADD_TER R1.1 "VCC"
  14. .TER U1.14
  15. U2.4
  16. U2.1
  17. U2.14
  18. P1.1
  19. .ADD_TER U1.2 "N-4"
  20. .TER U2.3
  21. .ADD_TER P1.2 "/SIG_OUT"
  22. .TER U2.5
  23. U2.2
  24. .ADD_TER R1.2 "/CLOCK_IN"
  25. .TER C1.1
  26. U1.1
  27. P1.3
  28. .END

Create an OrcadPCB2 netlist file

This format has only one section which is the footprint list. Each footprint includes its list of pads with reference to a net.

Here is the style-sheet for this specific conversion:

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!--XSL style sheet to Eeschema Generic Netlist Format to CADSTAR netlist format
  3. Copyright (C) 2010, SoftPLC Corporation.
  4. GPL v2.
  5. How to use:
  6. https://lists.launchpad.net/kicad-developers/msg05157.html
  7. -->
  8. <!DOCTYPE xsl:stylesheet [
  9. <!ENTITY nl "&#xd;&#xa;"> <!--new line CR, LF -->
  10. ]>
  11. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  12. <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
  13. <!--
  14. Netlist header
  15. Creates the entire netlist
  16. (can be seen as equivalent to main function in C
  17. -->
  18. <xsl:template match="/export">
  19. <xsl:text>( { Eeschema Netlist Version 1.1 </xsl:text>
  20. <!-- Generate line .TIM <time> -->
  21. <xsl:apply-templates select="design/date"/>
  22. <!-- Generate line eeschema version ... -->
  23. <xsl:apply-templates select="design/tool"/>
  24. <xsl:text>}&nl;</xsl:text>
  25. <!-- Generate the list of components -->
  26. <xsl:apply-templates select="components/comp"/> <!-- Generate list of components -->
  27. <!-- end of file -->
  28. <xsl:text>)&nl;*&nl;</xsl:text>
  29. </xsl:template>
  30. <!--
  31. Generate id in header like "eeschema (2010-08-17 BZR 2450)-unstable"
  32. -->
  33. <xsl:template match="tool">
  34. <xsl:apply-templates/>
  35. </xsl:template>
  36. <!--
  37. Generate date in header like "20/08/2010 10:45:33"
  38. -->
  39. <xsl:template match="date">
  40. <xsl:apply-templates/>
  41. <xsl:text>&nl;</xsl:text>
  42. </xsl:template>
  43. <!--
  44. This template read each component
  45. (path = /export/components/comp)
  46. creates lines:
  47. ( 3EBF7DBD $noname U1 74LS125
  48. ... pin list ...
  49. )
  50. and calls "create_pin_list" template to build the pin list
  51. -->
  52. <xsl:template match="comp">
  53. <xsl:text> ( </xsl:text>
  54. <xsl:choose>
  55. <xsl:when test = "tstamp != '' ">
  56. <xsl:apply-templates select="tstamp"/>
  57. </xsl:when>
  58. <xsl:otherwise>
  59. <xsl:text>00000000</xsl:text>
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. <xsl:text> </xsl:text>
  63. <xsl:choose>
  64. <xsl:when test = "footprint != '' ">
  65. <xsl:apply-templates select="footprint"/>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <xsl:text>$noname</xsl:text>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. <xsl:text> </xsl:text>
  72. <xsl:value-of select="@ref"/>
  73. <xsl:text> </xsl:text>
  74. <xsl:choose>
  75. <xsl:when test = "value != '' ">
  76. <xsl:apply-templates select="value"/>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:text>"~"</xsl:text>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. <xsl:text>&nl;</xsl:text>
  83. <xsl:call-template name="Search_pin_list" >
  84. <xsl:with-param name="cmplib_id" select="libsource/@part"/>
  85. <xsl:with-param name="cmp_ref" select="@ref"/>
  86. </xsl:call-template>
  87. <xsl:text> )&nl;</xsl:text>
  88. </xsl:template>
  89. <!--
  90. This template search for a given lib component description in list
  91. lib component descriptions are in /export/libparts,
  92. and each description start at ./libpart
  93. We search here for the list of pins of the given component
  94. This template has 2 parameters:
  95. "cmplib_id" (reference in libparts)
  96. "cmp_ref" (schematic reference of the given component)
  97. -->
  98. <xsl:template name="Search_pin_list" >
  99. <xsl:param name="cmplib_id" select="0" />
  100. <xsl:param name="cmp_ref" select="0" />
  101. <xsl:for-each select="/export/libparts/libpart">
  102. <xsl:if test = "@part = $cmplib_id ">
  103. <xsl:apply-templates name="build_pin_list" select="pins/pin">
  104. <xsl:with-param name="cmp_ref" select="$cmp_ref"/>
  105. </xsl:apply-templates>
  106. </xsl:if>
  107. </xsl:for-each>
  108. </xsl:template>
  109. <!--
  110. This template writes the pin list of a component
  111. from the pin list of the library description
  112. The pin list from library description is something like
  113. <pins>
  114. <pin num="1" type="passive"/>
  115. <pin num="2" type="passive"/>
  116. </pins>
  117. Output pin list is ( <pin num> <net name> )
  118. something like
  119. ( 1 VCC )
  120. ( 2 GND )
  121. -->
  122. <xsl:template name="build_pin_list" match="pin">
  123. <xsl:param name="cmp_ref" select="0" />
  124. <!-- write pin numner and separator -->
  125. <xsl:text> ( </xsl:text>
  126. <xsl:value-of select="@num"/>
  127. <xsl:text> </xsl:text>
  128. <!-- search net name in nets section and write it: -->
  129. <xsl:variable name="pinNum" select="@num" />
  130. <xsl:for-each select="/export/nets/net">
  131. <!-- net name is output only if there is more than one pin in net
  132. else use "?" as net name, so count items in this net
  133. -->
  134. <xsl:variable name="pinCnt" select="count(node)" />
  135. <xsl:apply-templates name="Search_pin_netname" select="node">
  136. <xsl:with-param name="cmp_ref" select="$cmp_ref"/>
  137. <xsl:with-param name="pin_cnt_in_net" select="$pinCnt"/>
  138. <xsl:with-param name="pin_num"> <xsl:value-of select="$pinNum"/>
  139. </xsl:with-param>
  140. </xsl:apply-templates>
  141. </xsl:for-each>
  142. <!-- close line -->
  143. <xsl:text> )&nl;</xsl:text>
  144. </xsl:template>
  145. <!--
  146. This template writes the pin netname of a given pin of a given component
  147. from the nets list
  148. The nets list description is something like
  149. <nets>
  150. <net code="1" name="GND">
  151. <node ref="J1" pin="20"/>
  152. <node ref="C2" pin="2"/>
  153. </net>
  154. <net code="2" name="">
  155. <node ref="U2" pin="11"/>
  156. </net>
  157. </nets>
  158. This template has 2 parameters:
  159. "cmp_ref" (schematic reference of the given component)
  160. "pin_num" (pin number)
  161. -->
  162. <xsl:template name="Search_pin_netname" match="node">
  163. <xsl:param name="cmp_ref" select="0" />
  164. <xsl:param name="pin_num" select="0" />
  165. <xsl:param name="pin_cnt_in_net" select="0" />
  166. <xsl:if test = "@ref = $cmp_ref ">
  167. <xsl:if test = "@pin = $pin_num">
  168. <!-- net name is output only if there is more than one pin in net
  169. else use "?" as net name
  170. -->
  171. <xsl:if test = "$pin_cnt_in_net>1">
  172. <xsl:choose>
  173. <!-- if a net has a name, use it,
  174. else build a name from its net code
  175. -->
  176. <xsl:when test = "../@name != '' ">
  177. <xsl:value-of select="../@name"/>
  178. </xsl:when>
  179. <xsl:otherwise>
  180. <xsl:text>$N-0</xsl:text><xsl:value-of select="../@code"/>
  181. </xsl:otherwise>
  182. </xsl:choose>
  183. </xsl:if>
  184. <xsl:if test = "$pin_cnt_in_net &lt;2">
  185. <xsl:text>?</xsl:text>
  186. </xsl:if>
  187. </xsl:if>
  188. </xsl:if>
  189. </xsl:template>
  190. </xsl:stylesheet>

Here is the OrcadPCB2 output file.

  1. ( { Eeschema Netlist Version 1.1 29/08/2010 21:07:51
  2. eeschema (2010-08-28 BZR 2458)-unstable}
  3. ( 4C6E2141 $noname P1 CONN_4
  4. ( 1 VCC )
  5. ( 2 /SIG_OUT )
  6. ( 3 /CLOCK_IN )
  7. ( 4 GND )
  8. )
  9. ( 4C6E20BA $noname U2 74LS74
  10. ( 1 VCC )
  11. ( 2 /SIG_OUT )
  12. ( 3 N-04 )
  13. ( 4 VCC )
  14. ( 5 /SIG_OUT )
  15. ( 6 ? )
  16. ( 7 GND )
  17. ( 14 VCC )
  18. )
  19. ( 4C6E20A6 $noname U1 74LS04
  20. ( 1 /CLOCK_IN )
  21. ( 2 N-04 )
  22. ( 7 GND )
  23. ( 14 VCC )
  24. )
  25. ( 4C6E2094 $noname C1 CP
  26. ( 1 /CLOCK_IN )
  27. ( 2 GND )
  28. )
  29. ( 4C6E208A $noname R1 R
  30. ( 1 VCC )
  31. ( 2 /CLOCK_IN )
  32. )
  33. )
  34. *

Eeschema plugins interface

Intermediate Netlist converters can be automatically launched within Eeschema.

Init the Dialog window

One can add a new netlist plug-in user interface tab by clicking on the Add Plugin button.

eeschema_plugin_add_plugin_png

Here is what the configuration data for the PadsPcb tab looks like:

eeschema_plugin_padspcb_png

Plugin Configuration Parameters

The Eeschema plug-in configuration dialog requires the following information:

  • The title: for instance, the name of the netlist format.

  • The command line to launch the converter.

Once you click on the netlist button the following will happen:

  1. Eeschema creates an intermediate netlist file *.xml, for instance test.xml.

  2. Eeschema runs the plug-in by reading test.xml and creates test.net.

Generate netlist files with the command line

Assuming we are using the program xsltproc.exe to apply the sheet style to the intermediate file, xsltproc.exe is executed with the following command:

xsltproc.exe -o <output filename> < style-sheet filename> <input XML file to convert>

In KiCad under Windows the command line is the following:

f:/kicad/bin/xsltproc.exe -o “%O” f:/kicad/bin/plugins/netlist_form_pads-pcb.xsl “%I”

Under Linux the command becomes as follows:

xsltproc -o “%O” /usr/local/kicad/bin/plugins/netlist_form_pads-pcb.xsl “%I”

Where netlist_form_pads-pcb.xsl is the style-sheet that you are applying. Do not forget the double quotes around the file names, this allows them to have spaces after the substitution by Eeschema.

The command line format accepts parameters for filenames:

The supported formatting parameters are.

  • %B ⇒ base filename and path of selected output file, minus path and extension.

  • %I ⇒ complete filename and path of the temporary input file (the intermediate net file).

  • %O ⇒ complete filename and path of the user chosen output file.

%I will be replaced by the actual intermediate file name

%O will be replaced by the actual output file name.

Command line format: example for xsltproc

The command line format for xsltproc is the following:

<path of xsltproc> xsltproc <xsltproc parameters>

under Windows:

f:/kicad/bin/xsltproc.exe -o “%O” f:/kicad/bin/plugins/netlist_form_pads-pcb.xsl “%I”

under Linux:

xsltproc -o “%O” /usr/local/kicad/bin/plugins/netlist_form_pads-pcb.xsl “%I”

The above examples assume xsltproc is installed on your PC under Windows and all files located in kicad/bin.

Bill of Materials Generation

Because the intermediate netlist file contains all information about used components, a BOM can be extracted from it. Here is the plug-in setup window (on Linux) to create a customized Bill Of Materials (BOM) file:

bom-netlist-tab_png

The path to the style sheet bom2csv.xsl is system dependent. The currently best XSLT style-sheet for BOM generation at this time is called bom2csv.xsl. You are free to modify it according to your needs, and if you develop something generally useful, ask that it become part of the KiCad project.

Command line format: example for python scripts

The command line format for python is something like:

python <script file name> <input filename> <output filename>

under Windows:

python *.exe f:/kicad/python/my_python_script.py “%I” “%O”

under Linux:

python /usr/local/kicad/python/my_python_script.py “%I” “%O”

Assuming python is installed on your PC.

Intermediate Netlist structure

This sample gives an idea of the netlist file format.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <export version="D">
  3. <design>
  4. <source>F:\kicad_aux\netlist_test\netlist_test.sch</source>
  5. <date>29/08/2010 21:07:51</date>
  6. <tool>eeschema (2010-08-28 BZR 2458)-unstable</tool>
  7. </design>
  8. <components>
  9. <comp ref="P1">
  10. <value>CONN_4</value>
  11. <libsource lib="conn" part="CONN_4"/>
  12. <sheetpath names="/" tstamps="/"/>
  13. <tstamp>4C6E2141</tstamp>
  14. </comp>
  15. <comp ref="U2">
  16. <value>74LS74</value>
  17. <libsource lib="74xx" part="74LS74"/>
  18. <sheetpath names="/" tstamps="/"/>
  19. <tstamp>4C6E20BA</tstamp>
  20. </comp>
  21. <comp ref="U1">
  22. <value>74LS04</value>
  23. <libsource lib="74xx" part="74LS04"/>
  24. <sheetpath names="/" tstamps="/"/>
  25. <tstamp>4C6E20A6</tstamp>
  26. </comp>
  27. <comp ref="C1">
  28. <value>CP</value>
  29. <libsource lib="device" part="CP"/>
  30. <sheetpath names="/" tstamps="/"/>
  31. <tstamp>4C6E2094</tstamp>
  32. <comp ref="R1">
  33. <value>R</value>
  34. <libsource lib="device" part="R"/>
  35. <sheetpath names="/" tstamps="/"/>
  36. <tstamp>4C6E208A</tstamp>
  37. </comp>
  38. </components>
  39. <libparts/>
  40. <libraries/>
  41. <nets>
  42. <net code="1" name="GND">
  43. <node ref="U1" pin="7"/>
  44. <node ref="C1" pin="2"/>
  45. <node ref="U2" pin="7"/>
  46. <node ref="P1" pin="4"/>
  47. </net>
  48. <net code="2" name="VCC">
  49. <node ref="R1" pin="1"/>
  50. <node ref="U1" pin="14"/>
  51. <node ref="U2" pin="4"/>
  52. <node ref="U2" pin="1"/>
  53. <node ref="U2" pin="14"/>
  54. <node ref="P1" pin="1"/>
  55. </net>
  56. <net code="3" name="">
  57. <node ref="U2" pin="6"/>
  58. </net>
  59. <net code="4" name="">
  60. <node ref="U1" pin="2"/>
  61. <node ref="U2" pin="3"/>
  62. </net>
  63. <net code="5" name="/SIG_OUT">
  64. <node ref="P1" pin="2"/>
  65. <node ref="U2" pin="5"/>
  66. <node ref="U2" pin="2"/>
  67. </net>
  68. <net code="6" name="/CLOCK_IN">
  69. <node ref="R1" pin="2"/>
  70. <node ref="C1" pin="1"/>
  71. <node ref="U1" pin="1"/>
  72. <node ref="P1" pin="3"/>
  73. </net>
  74. </nets>
  75. </export>

General netlist file structure

The intermediate Netlist accounts for five sections.

  • The header section.

  • The components section.

  • The lib parts section.

  • The libraries section.

  • The nets section.

The file content has the delimiter <export>

  1. <export version="D">
  2. ...
  3. </export>

The header section

The header has the delimiter <design>

  1. <design>
  2. <source>F:\kicad_aux\netlist_test\netlist_test.sch</source>
  3. <date>21/08/2010 08:12:08</date>
  4. <tool>eeschema (2010-08-09 BZR 2439)-unstable</tool>
  5. </design>

This section can be considered a comment section.

The components section

The component section has the delimiter <components>

  1. <components>
  2. <comp ref="P1">
  3. <value>CONN_4</value>
  4. <libsource lib="conn" part="CONN_4"/>
  5. <sheetpath names="/" tstamps="/"/>
  6. <tstamp>4C6E2141</tstamp>
  7. </comp>
  8. </components>

This section contains the list of components in your schematic. Each component is described like this:

  1. <comp ref="P1">
  2. <value>CONN_4</value>
  3. <libsource lib="conn" part="CONN_4"/>
  4. <sheetpath names="/" tstamps="/"/>
  5. <tstamp>4C6E2141</tstamp>
  6. </comp>
libsourcename of the lib where this component was found.

part

component name inside this library.

sheetpath

path of the sheet inside the hierarchy: identify the sheet within the full schematic hierarchy.

tstamps (time stamps)

time stamp of the schematic file.

tstamp (time stamp)

time stamp of the component.

Note about time stamps for components

To identify a component in a netlist and therefore on a board, the timestamp reference is used as unique for each component. However KiCad provides an auxiliary way to identify a component which is the corresponding footprint on the board. This allows the re-annotation of components in a schematic project and does not loose the link between the component and its footprint.

A time stamp is an unique identifier for each component or sheet in a schematic project. However, in complex hierarchies, the same sheet is used more than once, so this sheet contains components having the same time stamp.

A given sheet inside a complex hierarchy has an unique identifier: its sheetpath. A given component (inside a complex hierarchy) has an unique identifier: the sheetpath + its tstamp

The libparts section

The libparts section has the delimiter <libparts>, and the content of this section is defined in the schematic libraries. The libparts section contains

  • The allowed footprints names (names use wildcards) delimiter <fp>.

  • The fields defined in the library delimiter <fields>.

  • The list of pins delimiter <pins>.

  1. <libparts>
  2. <libpart lib="device" part="CP">
  3. <description>Condensateur polarise</description>
  4. <footprints>
  5. <fp>CP*</fp>
  6. <fp>SM*</fp>
  7. </footprints>
  8. <fields>
  9. <field name="Reference">C</field>
  10. <field name="Valeur">CP</field>
  11. </fields>
  12. <pins>
  13. <pin num="1" name="1" type="passive"/>
  14. <pin num="2" name="2" type="passive"/>
  15. </pins>
  16. </libpart>
  17. </libparts>

Lines like <pin num=”1” type=”passive”/> give also the electrical pin type. Possible electrical pin types are

Input

Usual input pin

Output

Usual output

Bidirectional

Input or Output

Tri-state

Bus input/output

Passive

Usual ends of passive components

Unspecified

Unknown electrical type

Power input

Power input of a component

Power output

Power output like a regulator output

Open collector

Open collector often found in analog comparators

Open emitter

Open emitter sometimes found in logic

Not connected

Must be left open in schematic

The libraries section

The libraries section has the delimiter <libraries>. This section contains the list of schematic libraries used in the project.

  1. <libraries>
  2. <library logical="device">
  3. <uri>F:\kicad\share\library\device.lib</uri>
  4. </library>
  5. <library logical="conn">
  6. <uri>F:\kicad\share\library\conn.lib</uri>
  7. </library>
  8. </libraries>

The nets section

The nets section has the delimiter <nets>. This section contains the “connectivity” of the schematic.

  1. <nets>
  2. <net code="1" name="GND">
  3. <node ref="U1" pin="7"/>
  4. <node ref="C1" pin="2"/>
  5. <node ref="U2" pin="7"/>
  6. <node ref="P1" pin="4"/>
  7. </net>
  8. <net code="2" name="VCC">
  9. <node ref="R1" pin="1"/>
  10. <node ref="U1" pin="14"/>
  11. <node ref="U2" pin="4"/>
  12. <node ref="U2" pin="1"/>
  13. <node ref="U2" pin="14"/>
  14. <node ref="P1" pin="1"/>
  15. </net>
  16. </nets>

This section lists all nets in the schematic.

A possible net contains the following.

  1. <net code="1" name="GND">
  2. <node ref="U1" pin="7"/>
  3. <node ref="C1" pin="2"/>
  4. <node ref="U2" pin="7"/>
  5. <node ref="P1" pin="4"/>
  6. </net>

net code

is an internal identifier for this net

name

is a name for this net

node

give a pin reference connected to this net

More about xsltproc

Refer to the page: http://xmlsoft.org/XSLT/xsltproc.html

Introduction

xsltproc is a command line tool for applying XSLT style-sheets to XML documents. While it was developed as part of the GNOME project, it can operate independently of the GNOME desktop.

xsltproc is invoked from the command line with the name of the style-sheet to be used followed by the name of the file or files to which the style-sheet is to be applied. It will use the standard input if a filename provided is - .

If a style-sheet is included in an XML document with a Style-sheet Processing Instruction, no style-sheet needs to be named in the command line. xsltproc will automatically detect the included style-sheet and use it. By default, the output is to stdout. You can specify a file for output using the -o option.

Synopsis

  1. xsltproc [[-V] | [-v] | [-o *file* ] | [--timing] | [--repeat] |
  2. [--debug] | [--novalid] | [--noout] | [--maxdepth *val* ] | [--html] |
  3. [--param *name* *value* ] | [--stringparam *name* *value* ] | [--nonet] |
  4. [--path *paths* ] | [--load-trace] | [--catalogs] | [--xinclude] |
  5. [--profile] | [--dumpextensions] | [--nowrite] | [--nomkdir] |
  6. [--writesubtree] | [--nodtdattr]] [ *stylesheet* ] [ *file1* ] [ *file2* ]
  7. [ *....* ]

Command line options

-V or --version

Show the version of libxml and libxslt used.

-v or --verbose

Output each step taken by xsltproc in processing the stylesheet and the document.

-o or --output file

Direct output to the file named file. For multiple outputs, also known as ``chunking’’, -o directory/ directs the output files to a specified directory. The directory must already exist.

--timing

Display the time used for parsing the stylesheet, parsing the document and applying the stylesheet and saving the result. Displayed in milliseconds.

--repeat

Run the transformation 20 times. Used for timing tests.

--debug

Output an XML tree of the transformed document for debugging purposes.

--novalid

Skip loading the document’s DTD.

--noout

Do not output the result.

--maxdepth value

Adjust the maximum depth of the template stack before libxslt concludes it is in an infinite loop. The default is 500.

--html

The input document is an HTML file.

--param name value

Pass a parameter of name name and value value to the stylesheet. You may pass multiple name/value pairs up to a maximum of 32. If the value being passed is a string rather than a node identifier, use —stringparam instead.

--stringparam name value

Pass a paramenter of name name and value value where value is a string rather than a node identifier. (Note: The string must be utf-8.)

--nonet

Do not use the Internet to fetch DTD’s, entities or documents.

--path paths

Use the list (separated by space or column) of filesystem paths specified by paths to load DTDs, entities or documents.

--load-trace

Display to stderr all the documents loaded during the processing.

--catalogs

Use the SGML catalog specified in SGML_CATALOG_FILES to resolve the location of external entities. By default, xsltproc looks for the catalog specified in XML_CATALOG_FILES. If that is not specified, it uses /etc/xml/catalog.

--xinclude

Process the input document using the Xinclude specification. More details on this can be found in the Xinclude specification: http://www.w3.org/TR/xinclude/

--profile —norman

Output profiling information detailing the amount of time spent in each part of the stylesheet. This is useful in optimizing stylesheet performance.

--dumpextensions

Dumps the list of all registered extensions to stdout.

--nowrite

Refuses to write to any file or resource.

--nomkdir

Refuses to create directories.

--writesubtree path

Allow file write only within the path subtree.

--nodtdattr

Do not apply default attributes from the document’s DTD.

Xsltproc return values

xsltproc returns a status number that can be quite useful when calling it within a script.

0: normal

1: no argument

2: too many parameters

3: unknown option

4: failed to parse the stylesheet

5: error in the stylesheet

6: error in one of the documents

7: unsupported xsl:output method

8: string parameter contains both quote and double-quotes

9: internal processing error

10: processing was stopped by a terminating message

11: could not write the result to the output file

More Information about xsltproc

libxml web page: http://www.xmlsoft.org/

W3C XSLT page: http://www.w3.org/TR/xslt