# 3.6.4.1 ArrangeLayers (macro)

Arranges all unlinked layers and linked layers having units percent-of-linked-layer into a specified number of rows and columns. Sets units of all layers to percent-of-page.

Assumes that the CheckMargins macro is executed just prior to its execution. Will not add layers to pad out up to (number of rows)*(number of columns) layers.

## Definition:

Def ArrangeLayers {
x = 100 - Left - Right - (%2-1)*xGap;
x/=%2;      // calculate width in % of page
y = 100 - Top - Bottom - (%1-1)*yGap;
y/=%1;// calculate height in % of page
if (x < 5 || y < 5) {
ty -b "Resulting layers are too small, operation aborted!";
break 1;
};
k = 0;
for (i = 1; i <= %1; i+=1) { // loop for %1 rows of layers
for (j = 1; j <= %2; j+=1) { // loop for %2 columns of layers
for (k+=1;k <=page.nlayers;k+=1) {
// loop through all layers in page
#!k=;
layer -s k;
if (layer.link == 0 || layer.unit != 7) break;
};  // or linked layers having units
layer -u 1;
if (%2==1) { // if only 1 column
layer x y [Left+(j-1)*(x+xGap)] [Top+(%1-i)*(y+yGap)];
}
else { // if more than 1 column
layer x y [Left+(j-1)*(x+xGap)] [Top+(i-1)*(y+yGap)];
};  // end else
};  // end columns for loop
};  // end rows loop
};  // end def

## Example:

This script arranges 12 unlinked layers in the active graph window into 4 rows and 3 columns. Note, again that CheckMargins must be run just before running ArrangeLayers.

CheckMargins;
ArrangeLayers 4 3;