Script Grep

Community Beginner ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

Hello to all
I would like to find/modify all the text on my pages and remove it by the findGrep and changeGrep method in a script, but only on one layer...

as if myLayer.ChangeGrep() exists?

 

Is it possible ?

 

Thx in advance for your help

 

My actual script :

var myDocument = app.documents.item(0);
//var myLayer = myDocument.layers.item("FauxTexte");
//Clear the find/change grep preferences. 
app.findGrepPreferences = NothingEnum.nothing; 
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options. 
app.findChangeGrepOptions.includeFootnotes = false; 
app.findChangeGrepOptions.includeHiddenLayers = false; 
app.findChangeGrepOptions.includeLockedLayersForFind = false; 
app.findChangeGrepOptions.includeLockedStoriesForFind = false; 
app.findChangeGrepOptions.includeMasterPages = false;
//Regular expression for finding an email address. 
app.findGrepPreferences.findWhat = '(?s)^.+'; 
app.changeGrepPreferences.changeTo = '';
//app.changeGrepPreferences.underline = true; 
myDocument.changeGrep();
//Clear the find/change preferences after the search. 
app.findGrepPreferences = NothingEnum.nothing; 
app.changeGrepPreferences = NothingEnum.nothing;

 

TOPICS
Scripting

Views

74

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Nov 15, 2021 Nov 15, 2021
Something like this, though it wouldn't work if you have anchored, grouped or otherwise nested frames in the layer. In that case, you'd probably just iterate through myDocuments.layers.itemByName("name").textFrames.everyItem().parentStory and change those.  var myLayerTexts = myDocument.layers.itemByName("your-layer-name").textFrames.everyItem().texts.everyItem(); myLayerTexts.changeGrep();

Likes

Translate

Translate
Adobe Community Professional , Nov 16, 2021 Nov 16, 2021
Hi Franck, simply lock all layers but the one(s) you are interested in. myDocument.layers.everItem().locked = true; myLayer.locked = false; // PERHAPS ALSO THIS: myLayer.pageItems.everyItem().locked = false; Then run your script with the document scope that you already have implemented. Note: myDocument.changeGrep() will also affect texts on the Parent Pages ( formerly called Master Pages ) . Regards, Uwe Laubender ( ACP )

Likes

Translate

Translate
Adobe Community Professional ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

Something like this, though it wouldn't work if you have anchored, grouped or otherwise nested frames in the layer. In that case, you'd probably just iterate through myDocuments.layers.itemByName("name").textFrames.everyItem().parentStory and change those. 

var myLayerTexts = myDocument.layers.itemByName("your-layer-name").textFrames.everyItem().texts.everyItem();

myLayerTexts.changeGrep();

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Hi Franck,

simply lock all layers but the one(s) you are interested in.

myDocument.layers.everItem().locked = true;
myLayer.locked = false;
// PERHAPS ALSO THIS:
myLayer.pageItems.everyItem().locked = false;

 

Then run your script with the document scope that you already have implemented.

 

Note:

myDocument.changeGrep()

will also affect texts on the Parent Pages ( formerly called Master Pages ) .

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

LATEST

Thanks both! This 2 solutions make the job!
Frank

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines