Skip to content

Instantly share code, notes, and snippets.

@psd psd/bom-json.ulp
Created Jul 25, 2011

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.