Page 1 of 1

How to target a layer other than the one currently selected

Posted: March 18th, 2018, 8:13 pm
by reubenlara
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!

Re: How to target a layer other than the one currently selected

Posted: March 18th, 2018, 9:21 pm
by wysee
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.

Re: How to target a layer other than the one currently selected

Posted: March 19th, 2018, 7:24 am
by reubenlara
Perfect, that worked great. Thanks so much!