Implementing the traverseLayers function from xtools stdlib.

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

ojodegato

Implementing the traverseLayers function from xtools stdlib.

Post 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
xbytor

Implementing the traverseLayers function from xtools stdlib.

Post 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);