Skip to content

Instantly share code, notes, and snippets.

@psd
Created July 25, 2011 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psd/1105043 to your computer and use it in GitHub Desktop.
Save psd/1105043 to your computer and use it in GitHub Desktop.
Eagle CAD save a Bill of Materials as JSON
#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");
}
}
@psd
Copy link
Author

psd commented Jul 25, 2011

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment