#usage "Arranges parts on board by schematic page.\n"
"
All parts from each schematic sheet are piled on top of each other at separate "
"locations on the board, one pile per sheet in the upper left quadrant of the layout.
"
"See distribute.ulp script to separate each pile of parts for the next stage of layout.
"
"Scripts are created in the subdirectory \"scripts\" in each project's folder. "
"Watch title bar for progress.
"
"Doug Wellington http://www.cadsoftusa.com/downloads/DougWellington";
string ScriptName = "ArrangePartsBySheet";
string Version = "1.00";
if (!schematic) {
dlgMessageBox(ScriptName + " " + Version + "Please start this ULP from the schematic.
" + usage);
exit(1);
}
int maxCols = 5; // How many groups before making another row?
int rowIncrement = 2000;
int colIncrement = 2000;
// Make sure to use a different quadrant than DistributeParts
int XQuadrant = -1; // Left
int YQuadrant = +1; // Top
string directory;
schematic (sch) {
directory = filedir(sch.name) + "scripts";
}
string a[];
int n = fileglob(a, directory);
string command;
if (n == 0){
sprintf(command, "mkdir %s", directory);
system(command);
}
int t = time();
string datestring;
sprintf(datestring, "%d%02d%02d-%02d%02d%02d", t2year(t), t2month(t), t2day(t), t2hour(t), t2minute(t), t2second(t) );
string scriptfile;
sprintf(scriptfile, "%s/%s-%s.scr", directory, ScriptName, datestring);
output(scriptfile) {
printf("board; \n");
printf("display -19;\n"); // Hide airwires
printf("grid mil 50;\n"); // Known grid state
schematic(SCH) {
int row = 1;
int col = 1;
SCH.sheets(S) {
int LocationX = col * colIncrement * XQuadrant;
int LocationY = row * rowIncrement * YQuadrant;
S.parts(P) {
if (P.device.package && P.name) {
printf("Move %s (%d %d);\n", P.name, LocationX, LocationY);
}
}
col += 1;
if (col > maxCols) {
col = 1;
row += 1;
}
}
}
printf("grid last;\n"); // Return grid state
printf("display +19;\n"); // Show airwires again
printf("window fit;\n"); // Fit everything into the window
}
sprintf(command, "script %s", scriptfile);
exit(command);