Copy link to clipboard
Copied
Hello!
Before the letter D, I try to insert a Column Break (in GREP is the character ^M) in my Index. But I can't because in GREP ^D means other thing and is not working the script.
Is important be sure don't damage other letters D
How can I add a column break before my single letter D ?
replaceText ("^D\r","^MD\r")
function replaceText (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
My actual Index:
The result I expect:
Thanks so much in advance!
You cannot use changeGrep with TextPreferences syntax.
This should work.
replaceText ("^(D)$","~M$1")
function replaceText (input, output)
{
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = input;
app.changeGrepPreferences.changeTo = output;
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
}
Have fun
Copy link to clipboard
Copied
Try this:
Have fun
Aktualisiert
(too much security)
^(D)$ is sufficient
Copy link to clipboard
Copied
Hi !
Is funny because in Indesign using the normal Panel Find/change is working.
But with my code is not working. Do you thing this kind of GREP are not working in the scripts? or maybe is something wrong in my script?
replaceText ("^(
)$","~M$1") function replaceText (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
Thanks a lot !
Copy link to clipboard
Copied
You cannot use changeGrep with TextPreferences syntax.
This should work.
replaceText ("^(D)$","~M$1")
function replaceText (input, output)
{
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = input;
app.changeGrepPreferences.changeTo = output;
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
}
Have fun
Copy link to clipboard
Copied
HI!
works excelent.
Deep thank you!
Copy link to clipboard
Copied
here my final script, maybe help to someone:
// Source: https://forums.adobe.com/thread/708641
// This Script allow you to find a replace a Text using 2 syntax FIND or GREP. Becarefull, affects the text of the entire document. The sintaxis of your queries are different if you use FIND or GREP, exaclty same like when you find and replace with the indesign window.
// https://helpx.adobe.com/indesign/using/find-change.html#find_and_change_objects
// To replace with GREP a simple Index Setion Heading, for example the letter D, you can use simple this ^(D)$ but if you want extra security use this ^(
)$ /******** FIND AND REPLACE TEXT USING GREP ********/
replaceTextUsingGREP ("^(
)$","~M$1"); // add a Break Column before letter D (Index Section Heading) function replaceTextUsingGREP (input, output)
{
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = input;
app.changeGrepPreferences.changeTo = output;
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
}
/******** FIND AND REPLACE TEXT USING FIND ********/
replaceTextUsingFIND ("yourText", "^MyourText"); //add a Break Column
replaceTextUsingFIND ("yourText2\r", "yourText2\r"); // add many queries as you want
function replaceTextUsingFIND (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
Copy link to clipboard
Copied
You're welcome.
(But please change 'extra security' to 'unnecessary'.)
Copy link to clipboard
Copied
Here the final code, thanks to pixxxel schubser!
// Source: https://forums.adobe.com/thread/708641
// This Script allow you to find a replace a Text using 2 syntax FIND or GREP. Becareful, affects the text of the entire document. The sintaxis of your queries are different if you use FIND or GREP, exactly same like when you find and replace with the indesign window.
// https://helpx.adobe.com/indesign/using/find-change.html#find_and_change_objects
// To replace with GREP a simple Index Section Heading, for example the letter D, you can use simple this ^(D)$ but if you want unnecessary use this ^(
)$ /******** FIND AND REPLACE TEXT USING GREP ********/
replaceTextUsingGREP ("^(D)$","~M$1"); // add a Break Column before letter D (Index Section Heading)
function replaceTextUsingGREP (input, output)
{
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = input;
app.changeGrepPreferences.changeTo = output;
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
}
/******** FIND AND REPLACE TEXT USING FIND ********/
replaceTextUsingFIND ("yourText", "^MyourText"); //add a Break Column
replaceTextUsingFIND ("yourText2\r", "yourText2\r"); // add many queries as you want
function replaceTextUsingFIND (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
Copy link to clipboard
Copied
manuelb27477138 schrieb
… you can use simple this ^(D)$ but if you want unnecessary use this ^(
)$ …
That's really funny. I'm amused. Thank you