Skip to main content
Known Participant
May 20, 2014
Answered

Find and change all layers

  • May 20, 2014
  • 2 replies
  • 386 views

Hi All,

How can I find and change in all layers if layer hidden

app.findGrepPreferences.findWhat = "\\s\\s+  ";

app.changeGrepPreferences.changeTo = " ";

app.changeGrep();

app.findGrepPreferences = app.changeGrepPreferences = null;

Thanks

Steve

This topic has been closed for replies.
Correct answer Harbs.

app.findChangeGrepOptions.includeHiddenLayers = true;

2 replies

Community Expert
May 20, 2014

@Steve – check the variable visible for all layers in the document, store some information about that layers, set visibility of all layers to true, search, replace, set back the original visibility of all layers.

Like that with storing the unique ID for invisible layers in an array:

//Temporarily make all non-visible layers visible

//Search and replace

//Set the visibility of all layers back again

//If you want to access locked layers as well, expand this example.

//1. Store all IDs of all hidden layers in array:

var myDoc = app.documents[0];

var allHiddenLayersID = new Array();

var allLayers = myDoc.layers;

for(var n=0;n<allLayers.length;n++){

    if(!allLayers.visible){allHiddenLayersID.push(allLayers.id)};

    };

//2. Set all layers of document to visible:

myDoc.layers.everyItem().visible = true;

//3. Do your search/replace

app.findGrepPreferences.findWhat = "\\s\\s+  ";

app.changeGrepPreferences.changeTo = " ";

app.changeGrep();

app.findGrepPreferences = app.changeGrepPreferences = null;

//4. Change all formerly hidden layers back to visible = false:

for(var n=0;n<allHiddenLayersID.length;n++){

    myDoc.layers.itemByID(allHiddenLayersID).visible = false;

    };

Locked layers will not be searched.

If you want that, you could expand this example with a second array for locked is true.

Uwe

Community Expert
May 20, 2014

Yeah. Harbs is right. There is an easy control in the findChangeGrepOptions. Much faster.

Of course after the search/replace set it back to its original value.

For locked layers change my example to the variable locked instead of visible.

Uwe

Harbs.
Harbs.Correct answer
Legend
May 20, 2014

app.findChangeGrepOptions.includeHiddenLayers = true;