Skip to content

Instantly share code, notes, and snippets.

@unycone
Created March 25, 2013 12:28
Show Gist options
  • Save unycone/5236786 to your computer and use it in GitHub Desktop.
Save unycone/5236786 to your computer and use it in GitHub Desktop.
This AfterEffects script sorts layers in a composition according to their in-points.
/*
* This AfterEffects script sorts layers in a composition according to their in-points.
*
* 1. Save this file as "sortlayers.jsx".
* 2. Select a target composition in project panel of your AfterEffects.
* 3. Run "sortlayers.jsx" from Menu->"File"->"Scripts"->"Run Script File".
*/
app.beginUndoGroup("Sort layers");
var item = app.project.activeItem;
if (item != null && item instanceof CompItem) {
for (var i = 1; i <= item.layers.length; ++i) {
var cur = i;
while (true) {
if (cur-1 > 0 && item.layers[cur].inPoint > item.layers[cur-1].inPoint) {
item.layers[cur].moveBefore(item.layers[cur-1]);
--cur;
}
else {
break;
}
}
}
}
else {
alert("Choose a target comp in project panel.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment