Implementing the traverseLayers function from xtools stdlib.

Discussion of the xtools Toolkit

Moderators: xbytor, DavideBarranca, Paul MR

ojodegato

Implementing the traverseLayers function from xtools stdlib.

Postby ojodegato » Wed Jul 02, 2014 1:05 am

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.

Postby xbytor » Wed Jul 02, 2014 6:57 pm

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


Return to “xtools”

Who is online

Users browsing this forum: No registered users and 12 guests