Skip to content

Instantly share code, notes, and snippets.

@dokluch
Last active August 29, 2015 14:10
Show Gist options
  • Save dokluch/36d417e5470ed24f5f2b to your computer and use it in GitHub Desktop.
Save dokluch/36d417e5470ed24f5f2b to your computer and use it in GitHub Desktop.
Creates a null object parented to all selected layers in Adobe After Effects
function createNull(){
var activeComp = app.project.activeItem;
if(!activeComp instanceof CompItem || !activeComp){
alert("No comp selected");
return null;
}
app.beginUndoGroup("Creatin a null");
if(activeComp.selectedLayers.length != 0){//и если на композиции выделены какие-то слои
var sel = activeComp.selectedLayers;
//сортируем по убыванию
sel.sort(function(a,b){
return a.index - b.index;
});
//создаем нуль и кидаем выше самого верхнего
var newNull = activeComp.layers.addNull(activeComp.duration);
newNull.moveBefore(sel[0]);
for(var l = 0; l < sel.length; l++){
sel[i].parent = newNull;//привязываемся ко всем выбранным слоям
}
}
else var newNull = activeComp.layers.addNull(activeComp.duration);//создаем нулл
app.endUndoGroup();
}
createNull();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment