<!--XSL style sheet to convert EESCHEMA XML Partlist Format to grouped CSV BOM Format | |
Copyright (C) 2014, Wolf Walter. | |
Copyright (C) 2013, Stefan Helmert. | |
Copyright (C) 2018, Kicad developers. | |
Copyright (C) 2019, arturo182. | |
GPL v2. | |
Functionality: | |
Generation of JLCPCB PCBA compatible BOM | |
How to use this is explained in eeschema.pdf chapter 14. You enter a command line into the | |
netlist exporter using a new (custom) tab in the netlist export dialog. | |
The command line is | |
xsltproc -o "%O.csv" "FullPathToFile/bom2grouped_csv_jlcpcb.xsl" "%I" | |
--> | |
<!-- | |
@package | |
Generates a JLCPCB PCBA service compatible BOM | |
Functionality: | |
* Generate a comma separated value BOM list (csv file type). | |
* Components are sorted by ref and grouped by same value+footprint | |
One value per line | |
Fields are | |
Comment,Designator,Footprint,LCSC | |
The command line is | |
xsltproc -o "%O.csv" "full_path/bom2grouped_csv_jlcpcb.xsl" "%I" | |
--> | |
<!DOCTYPE xsl:stylesheet [ | |
<!ENTITY nl "
"> <!--new line CR, LF, or LF, your choice --> | |
]> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
<xsl:output method="text"/> | |
<xsl:variable name="digits" select="'1234567890'" /> | |
<!-- for matching grouping of footprint and value combination --> | |
<xsl:key name="partTypeByValueAndFootprint" match="comp" use="concat(footprint, '-', value)" /> | |
<!-- for table head and empty table fields--> | |
<xsl:key name="headentr" match="field" use="@name"/> | |
<!-- main part --> | |
<xsl:template match="/export"> | |
<xsl:text>Comment,Designator,Footprint,LCSC</xsl:text> | |
<!-- all table entries --> | |
<xsl:apply-templates select="components"/> | |
</xsl:template> | |
<xsl:template match="components"> | |
<!-- for Muenchian grouping of footprint and value combination --> | |
<xsl:for-each select="comp[count(. | key('partTypeByValueAndFootprint', concat(footprint, '-', value))[1]) = 1]"> | |
<xsl:sort select="@ref" /> | |
<xsl:text>&nl;</xsl:text> | |
<xsl:text>"</xsl:text><xsl:value-of select="value"/><xsl:text>","</xsl:text> | |
<!-- list of all references --> | |
<xsl:for-each select="key('partTypeByValueAndFootprint', concat(footprint, '-', value))"> | |
<!-- strip non-digits from reference and sort based on remaining number --> | |
<xsl:sort select="translate(@ref, translate(@ref, $digits, ''), '')" data-type="number" /> | |
<xsl:value-of select="@ref"/> | |
<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if> | |
</xsl:for-each> | |
<xsl:text>","</xsl:text> | |
<xsl:value-of select="footprint"/><xsl:text>","</xsl:text> | |
<xsl:value-of select="fields/field[@name='LCSC']"/><xsl:text>"</xsl:text> | |
</xsl:for-each> | |
</xsl:template> | |
<!-- table entries with dynamic table head --> | |
<xsl:template match="fields"> | |
<!-- remember current fields section --> | |
<xsl:variable name="fieldvar" select="field"/> | |
<!-- for all existing head entries --> | |
<xsl:for-each select="/export/components/comp/fields/field[generate-id(.) = generate-id(key('headentr',@name)[1])]"> | |
<xsl:variable name="allnames" select="@name"/> | |
<xsl:text>,"</xsl:text> | |
<!-- for all field entries in the remembered fields section --> | |
<xsl:for-each select="$fieldvar"> | |
<!-- only if this field entry exists in this fields section --> | |
<xsl:if test="@name=$allnames"> | |
<!-- content of the field --> | |
<xsl:value-of select="."/> | |
</xsl:if> | |
<!-- | |
If it does not exist, use an empty cell in output for this row. | |
Every non-blank entry is assigned to its proper column. | |
--> | |
</xsl:for-each> | |
<xsl:text>"</xsl:text> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
This comment has been minimized.
This comment has been minimized.
FIXED. It was the spaces in the path. I just edited the first argument as a test and that succeed. Run command: ****** My original post ****** Any idea how to get around Onedrive hijacking my system paths? I get the following error message below. Thank you for any help Run command: Command error. Return code 11 |
This comment has been minimized.
This comment has been minimized.
Same comment as @MauroMombelli - would be great if the part already has LCSC defined to use that value instead of having an empty "LCSC" column and then a 2nd "LCSC" column. |
This comment has been minimized.
This comment has been minimized.
HI folks, Run command: Command error. Return code -1 Error messages: ` |
This comment has been minimized.
This comment has been minimized.
Hi everyone, sorry for the late reply, I have now fixed the double LCSC column issue, should be all good :) |
This comment has been minimized.
This comment has been minimized.
Using Win10 and KiCad 5.1.5-3 I had to shorten the path length and remove spaces in all arguments to successfully generate a BOM file. The file also did not have any extension after being generated, but once renaming the file with a csv extension, I was able to upload it to JCBPCB successfully. |
This comment has been minimized.
This comment has been minimized.
Hi. I'm getting this error when doing an export. I/O error : Invalid argument |
This comment has been minimized.
This comment has been minimized.
Having the same problem getting : |
This comment has been minimized.
This comment has been minimized.
guys, if you have problem, what version of kicad and what os? |
This comment has been minimized.
This comment has been minimized.
I have the same issue Running KiCAd 5.1.6-1 |
This comment has been minimized.
This comment has been minimized.
The script has trouble with spaces on Windows. Move it to a (full path) without spaces worked for me. |
This comment has been minimized.
This comment has been minimized.
I/O error : Invalid argument Still present Windows 10 Kicad 5.1.8-1 |
This comment has been minimized.
This comment has been minimized.
Like mentioned above, it seems xsltproc doesn't like spaces in paths so try removing those. |
This comment has been minimized.
This comment has been minimized.
hey my command line is: no spaces there ^_^ |
This comment has been minimized.
This comment has been minimized.
haha it was the slashes i only realized after typing it out here lol |
This comment has been minimized.
This comment has been minimized.
I've had the same problem with spaces in the file name. Some of the plugin for KiCAD are python scripts - and they run okay. The plugins which depend on xsltproc fail on windows systems that have spaces in the file names. Just changing the directories to remove spaces in file names or altering the directory structure to remove spaces may then break behind the scene links for other parts libraries and custom parts. Is there a way to pre-process the source and output file name strings before substituting into the command line such that the strings are passed as a URI.? From the explanation on stackover flow: "Most XPath and XSLT functions work with URIs and not with system/os dependent file paths so you might try to convert your Windows file path to a URI with e.g. unparsed-text(concat('file:///', replace(replace($pathToCSV, '\', '/'), ' ', '%20')))" https://stackoverflow.com/questions/61119536/xsl-transform-filepath-with-spaces |
This comment has been minimized.
This comment has been minimized.
Hi, How to get a quantity column? The components are grouped but have no quantity column. |
This comment has been minimized.
This comment has been minimized.
Can the code of the plugin that already has the quantity column be used as an example to add the quantity column in this plugin to JLCPCB?
|
This comment has been minimized.
This comment has been minimized.
I managed to find a formula to count the commas so I added 1 to the result. Cell "X4": C2,C3,C4,C8,C9,C42,C43,C44 Formula =LEN(X4)-LEN(SUBSTITUTE(X4;",";""))+1 Result: 8 |
This comment has been minimized.
Ciao,
my component already have the field LCSC, the file generated does generate an empty "LCSC" column and add a space in front " LCSC".
Eeschema 5.1.6