Copy link to clipboard
Copied
Hello !
My idea is to remove the PlaceHolder text to have a clean text area. To do this, Grep should help me.
If I use the Find/Chnage box and do a search on
\KLorem\X+
to replace it with "" (nothing) : it does the job, all my texts that start with Lorem will be deleted (even if it's linked box, even if there is some overset text)
VS
If I use javascript :
app.findGrepPreferences.findWhat = '\\KLorem\\X+';
the result is partial if my text is linked in several text box.
So, how to select all strory in javascript, if the first word is Lorem ?
Here my actual javascript code :
var myDocument = app.documents.item(0);
try {
var myLayerTexts = myDocument.layers.itemByName("Texte").textFrames.everyItem().texts.everyItem();
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;
app.findGrepPreferences.findWhat = '\\KLorem\\X+';
app.changeGrepPreferences.changeTo = '';
myLayerTexts.changeGrep();
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
}
catch (e) {
alert("Le calque Texte est vide ou n'existe pas");
}
1 Correct answer
You could try the following
var myDocument = app.documents.item(0);
try {
var myLayerTexts = myDocument.layers.itemByName("Texte").textFrames.everyItem().parentStory
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.includeLockedS
...
Copy link to clipboard
Copied
Hi Frank,
to give some advice we need a minimum sample InDesign document for testing where you see the issue.
And a screenshot of your GREP Find/Replace settings when you run your expression in the UI.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
You're right! Sorry
Here my starter document.
 In this second screen, this is the result from the UI : (it's delete only the first box)
 And this one, is the selection from the Find/Change box : it's delete all the text
Attached, an indesign example
Thanks in advance fo any help
Regards
Frank
 
Copy link to clipboard
Copied
You could try the following
var myDocument = app.documents.item(0);
try {
var myLayerTexts = myDocument.layers.itemByName("Texte").textFrames.everyItem().parentStory
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;
app.findGrepPreferences.findWhat = '\\KLorem\\X+';
app.changeGrepPreferences.changeTo = '';
for(var i = 0; i < myLayerTexts.length; i++)
myLayerTexts[i].changeGrep();
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
}
catch (e) {
alert("Le calque Texte est vide ou n'existe pas");
}
The issue with your code is that you are executing the grep over the texts object. The texts object for each frame will contain only the text within that frame and hence the condition will fail for the linked frames. What I have done is executing the grep on all the stories corresponding to the frames in the layer of interest. This will work but is a bit unoptimised as the loop will be called for each frame in a threaded story when its sufficient to call it once.
-Manan
Copy link to clipboard
Copied
Ok, many many thanks for your help !
It works now. Even if the code has not been optimized: for 6 or 8 pages of a magazine, it's a good thing.
Frank

