Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
reubenlara
Topic Author
Posts: 6
Joined: Fri Mar 16, 2018 6:22 am

How to target a layer other than the one currently selected

Sun Mar 18, 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:

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: Mon Nov 21, 2016 9:24 am

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

Sun Mar 18, 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
Topic Author
Posts: 6
Joined: Fri Mar 16, 2018 6:22 am

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

Mon Mar 19, 2018 7:24 am

Perfect, that worked great. Thanks so much!

Who is online

Users browsing this forum: No registered users and 4 guests