Skip to content

Instantly share code, notes, and snippets.

@u27a4
Created April 21, 2019 14:12
Show Gist options
  • Save u27a4/e1c76d09037ce2a1b6606e68a0b3080d to your computer and use it in GitHub Desktop.
Save u27a4/e1c76d09037ce2a1b6606e68a0b3080d to your computer and use it in GitHub Desktop.
aescript; arrange selected layers in a grid.
function gridarrange(comp, layerIndicies)
{
var d = Math.ceil(Math.sqrt(layerIndicies.length));
var w = comp.width / d;
var h = comp.height / d;
for (var i = 0; i < layerIndicies.length; i++)
{
var x = i % d;
var y = Math.floor(i / d);
comp.layers.precompose([layerIndicies[i]], comp.layers[i+1].name, true);
var precomposed = comp.layers[layerIndicies[i]];
precomposed.transform.scale.setValue([100 / d, 100 / d]);
precomposed.transform.position.setValue([w / 2 + w * x, h / 2 + h * y]);
}
}
app.beginUndoGroup("gridarrange");
var item = app.project.activeItem;
var layerIndicies = [];
for (var i = 0; i < item.selectedLayers.length; i++)
{
layerIndicies.push(item.selectedLayers[i].index);
}
gridarrange(item, layerIndicies);
app.endUndoGroup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment