Page 1 of 1

Select all abobe/below layers

Posted: September 29th, 2012, 12:26 pm
by yanez
Hallo is there any "select all above/below layers"?
Let's say i have a timeline with 100 layers, and i need to insert other 10 layer above the 50th layer.
So i need to select all 49 layers above the 50th and move all them forward in the timeline.
I would like to select the 49th layer and then run a script to add to selection all above layers
without usign the mouse. Thanks

Re: Select all abobe/below layers

Posted: September 29th, 2012, 1:21 pm
by Klustre
You can't select a layer, so you'd directly have to go into moving the layers in the timeline. Is this a fixed value every time?

Re: Select all abobe/below layers

Posted: September 30th, 2012, 4:26 am
by Paul Tuersley
Here's a script that will select all layers above a single selected layer. It would be pretty easy to adjust it to do different things. Really you need a script that presents a UI to offer different options, but it isn't really worth the effort. You can just use the Shift key to select a range of layers which would usually be quicker than using a script anyway.

Code: Select all

var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
	if (activeItem.selectedLayers.length > 0) {
		var selectedIndex = activeItem.selectedLayers[0].index-1;
		while (selectedIndex > 0) {
			activeItem.layer(selectedIndex).selected = true;
			selectedIndex --;
		}
	}
}

Re: Select all abobe/below layers

Posted: September 30th, 2012, 5:03 am
by Klustre
Oh, nice! Didn't know you could use .selected with layers as well.

Re: Select all abobe/below layers

Posted: September 30th, 2012, 5:50 am
by yanez
Paul Tuersley wrote:Here's a script that will select all layers above a single selected layer...
Thanks very much i will assign a shortcut. Ctrl alt shift UpArrow.

Re: Select all abobe/below layers

Posted: February 26th, 2014, 8:58 am
by benjapo
Paul Tuersley wrote:Here's a script that will select all layers above a single selected layer. It would be pretty easy to adjust it to do different things. Really you need a script that presents a UI to offer different options, but it isn't really worth the effort. You can just use the Shift key to select a range of layers which would usually be quicker than using a script anyway.

Hi Paul,

I'm attempting to tweak your script to select all layers below. It currently works, but I'm getting an "out of range" error after running it. Any advice on how to clean this up?
Thanks!

Code: Select all

var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
   if (activeItem.selectedLayers.length > 0) {
      var selectedIndex = activeItem.selectedLayers[0].index+1;
      while (selectedIndex > 0) {
         activeItem.layer(selectedIndex).selected = true;
         selectedIndex ++;
         
      }
   }
}

Re: Select all abobe/below layers

Posted: February 26th, 2014, 9:11 am
by Paul Tuersley
Because you're now going down the layers instead of up you need to stop when you pass the last layer index, not the first. So the 'while' line should be:

Code: Select all

while (selectedIndex <= activeItem.numLayers) {

Re: Select all abobe/below layers

Posted: February 26th, 2014, 9:23 am
by benjapo
Beautiful. Thanks for the quick response!

Re: Select all abobe/below layers

Posted: February 6th, 2018, 11:32 am
by apeshake
Hey, a bit late to the party but i just came across this thread and modified your script to make a select layers after playhead script I'd been searching for;

Code: Select all

{
var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
      var selectedIndex = 1;
      while (selectedIndex <= activeItem.numLayers) {
          if (activeItem.layer(selectedIndex).inPoint > activeItem.time) {
            activeItem.layer(selectedIndex).selected = true;
          } else {
            activeItem.layer(selectedIndex).selected = false;
          }
        selectedIndex ++;
      }
}
}
and one for before the playhead;

Code: Select all

{
var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
      var selectedIndex = activeItem.numLayers;
      while (selectedIndex > 0) {
          if (activeItem.layer(selectedIndex).inPoint < activeItem.time) {
            activeItem.layer(selectedIndex).selected = true;
          } else {
            activeItem.layer(selectedIndex).selected = false;
          }
        selectedIndex --;
      }
}
}
and just for good measure AT the playhead (not sure if i'll ever need this one...);

Code: Select all

{
var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
      var selectedIndex = activeItem.numLayers;
      while (selectedIndex > 0) {
          if (activeItem.layer(selectedIndex).inPoint == activeItem.time) {
            activeItem.layer(selectedIndex).selected = true;
          } else {
            activeItem.layer(selectedIndex).selected = false;
          }
        selectedIndex --;
      }
}
}
thanks Paul

Re: Select all abobe/below layers

Posted: February 11th, 2022, 5:23 am
by stanixlao

Even later for the party, but here's my generalized function :D

Code: Select all

function getLayersByIdx(idx,mode){
    //by neex2022 - supports 3 modes: after (or 1), before (or 2), except (or 2) specified index (idx)
   var activeItem = app.project.activeItem;
    if (activeItem != null && activeItem instanceof CompItem) {
        for(var j=1; j<=activeItem.numLayers; j++){
            var cond=false;
            (mode=="after"||mode==1)?cond=(j>idx):null;
            (mode=="before"||mode==2)?cond=(j<idx):null;  
            (mode=="except"||mode==3)?cond=(j!=idx):null;  
            activeItem.layer(j).selected = cond;
        }
        return activeItem.selectedLayers;
    }  
}