Select all abobe/below layers

What type of scripts do you need?

Moderator: byronnash

Post Reply
yanez
Posts: 9
Joined: July 31st, 2005, 8:52 am

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
Klustre
Posts: 21
Joined: July 27th, 2011, 2:53 am

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?
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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 --;
		}
	}
}
Klustre
Posts: 21
Joined: July 27th, 2011, 2:53 am

Oh, nice! Didn't know you could use .selected with layers as well.
yanez
Posts: 9
Joined: July 31st, 2005, 8:52 am

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.
benjapo
Posts: 3
Joined: February 21st, 2014, 9:24 am

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 ++;
         
      }
   }
}
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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) {
benjapo
Posts: 3
Joined: February 21st, 2014, 9:24 am

Beautiful. Thanks for the quick response!
apeshake
Posts: 1
Joined: February 6th, 2018, 11:26 am

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
stanixlao
Posts: 1
Joined: February 11th, 2022, 5:17 am

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;
    }  
}    
Post Reply