Page 1 of 1

Implementing the traverseLayers function from xtools stdlib.

Posted: Wed Jul 02, 2014 1:05 am
by ojodegato
I am trying to figure how to make a script which can search for a specific layer name in the layer palette, layer group and nested layer groups in PSCC 2014.
I came across the xtools traverse layer function in the sdlib.js which might do the job. How to implement this function was not clear to me.
I would like to ask help from the scripting community to figure out how apply to this function to a script. I am not a programer and have basic javascript knowledge.
Thanks in advance

Implementing the traverseLayers function from xtools stdlib.

Posted: Wed Jul 02, 2014 6:57 pm
by xbytor
The function you pass in would look something like this:

Code: Select all// find a layer in the document with a specified name and make it the active layer
function findLayerByName(doc, layer) {
   if (layer.name == "Desired Layer Name") {
     doc.activeLayer = layer;
     return false; // return false to stop the traversal
   }

   return true;  // keep on looking
}

Stdlib.traverseLayers(doc, findLayerByName, false, false);