How to target a layer other than the one currently selected

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
reubenlara
Posts: 6
Joined: March 16th, 2018, 6:22 am

March 18th, 2018, 8:13 pm

I have a scenario where i need to be actively working on a specific layer, but need to target another one that is not selected (in my case, a layer called "HAND"). I've already set up a ScriptUI panel with buttons to add the markers and have it working fine, but you have to select the "HAND" layer first, like this:

Code: Select all

var mySelection = app.project.activeItem.selectedLayers;
var compMarker = new MarkerValue("myMarker");
compMarker.duration = 2;
mySelection[0].Marker.setValueAtTime(app.project.activeItem.time, compMarker);
How do I change the variable "mySelection" so that I can be working on an arbitrary layer and have the markers always get added to the layer called "HAND"? Thanks!
wysee
Posts: 7
Joined: November 21st, 2016, 9:24 am

March 18th, 2018, 9:21 pm

you can loop through the layers to find the one named "Hand".
this will return a layer with a specific name, assuming you only have one layer with Hand in the name
this is case sensitive.

var handLayer = findLayer(app.project.activeItem,"hand")

function findLayer(curComp,name){
 for(i=1; i<=curComp.numLayers;i++){
   var curItem= curComp.layer(i);
   if(curItem.name===name){
     return curItem;
   }
 }
}


edit : make sure you check a layer is found before doing anything else.
reubenlara
Posts: 6
Joined: March 16th, 2018, 6:22 am

March 19th, 2018, 7:24 am

Perfect, that worked great. Thanks so much!
Post Reply