Created
July 25, 2011 20:02
-
-
Save psd/1105043 to your computer and use it in GitHub Desktop.
Eagle CAD save a Bill of Materials as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 4.1105 | |
#usage "en: <b>Export a Bill Of Materials as JSON</b>\n" | |
"<p>" | |
" Saves a project's <i>Bill Of Material</i> as a <i>project</i>.json" | |
" suitable for uploading to http://solderpad.com" | |
" <author>Author: psd@solderpad.com</author>" | |
"</p>"; | |
if (!schematic) { | |
dlgMessageBox(usage + "<hr><b>ERROR: No schematic!</b><p>\nThis program can only work in the schematic editor."); | |
exit(1); | |
} | |
schematic(SCH) { | |
string FileName; | |
string json; | |
string sep = ""; | |
FileName = filesetext("bom", ".json"); | |
output(FileName, "wt") { | |
printf("{\n"); | |
printf("\t\"items\": [\n"); | |
SCH.parts(P) { | |
if (P.device.package) { | |
json = sep + "\t\t{\n" | |
+ "\t\t\t\"designator\": \"" + P.name + "\",\n" | |
+ "\t\t\t\"value\": \"" + P.value + "\",\n" | |
+ "\t\t\t\"description\": \"" + P.device.headline + "\"\n" | |
+ "\t\t}"; | |
sep = ",\n"; | |
printf("%s", json); | |
} | |
} | |
printf("\n\t]\n}\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open a .sch file in Eagle, and run this script. Generates a .json file without any prompting meaning it runs from the command line, e.g.:
$ eagle -C'RUN bom-json.ulp; QUIT;' foo.sch