Copy link to clipboard
Copied
We have some set of texts that need to find and change in the entire InDesign CS4 document rather than doing manually. Kindly help me out to do the same successfully.
for e.g. find text - "mam" and replace with "man".
Copy link to clipboard
Copied
Hey!
This will do what you want:
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "mam";
app.changeTextPreferences.changeTo = "man";//this will show changes count
alert(app.activeDocument.changeText().length);
app.activeDocument.changeText();
--
tomaxxi
http://indisnip.wordpress.com/
Copy link to clipboard
Copied
Try below code if you have multiple texts for replace.
replaceText ("mam", "man");
replaceText ("mam1", "man1");
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;
}
Shonky
Copy link to clipboard
Copied
Thanks for sending us the wonderful script. I need one more help on this.
I need to find the character with the specific font and change to specific font
or
I need to find the character with the specific style and change to specific style
Please help the same to do successfully.
Copy link to clipboard
Copied
Hey!
This is little extended version of script that Shonky wrote. You can search/find for text, paragraph styles, character styles, or in combination.
findChange(/*find text*/ 'mam', /*change to text*/ 'man', /*old style*/ '', /*new style*/ '', /*old char style*/ 'Bold Text', /*new char style*/ 'Extended Bold Text');
function findChange (findWhat, changeTo, findStyle, changeStyle, findChrStyle, changeChrStyle){
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
if(findWhat)app.findTextPreferences.findWhat = findWhat;
if(changeTo)app.changeTextPreferences.changeTo = changeTo;
if(findStyle)app.findTextPreferences.appliedParagraphStyle = findStyle;
if(changeStyle)app.changeTextPreferences.appliedParagraphStyle = changeStyle;
if(findChrStyle)app.findTextPreferences.appliedCharacterStyle = findChrStyle;
if(changeChrStyle)app.changeTextPreferences.appliedCharacterStyle = changeChrStyle;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
Hope it helps!
--
tomaxxi
http://indisnip.wordpress.com/
Copy link to clipboard
Copied
Hi Marijan Tompa,
Can you help me?
How to find superscript?
My complete script is here:
replace ("(.+)", "Italic", "", "SRF Cyan", "", "SRF_it");
replace ("(.+)", "Italic", "", "", "", "_it");
replace ("(.+)", "Bold", "", "SRF Cyan", "", "SRF_bld");
replace ("(.+)", "Bold", "", "", "", "_bld");
//replace ("(.+)", "", "position", "", "_^$1", "");
//replace ("", "", "", "", "", "");
function replace(findWhat, fontStyle, position, fillColor, changeTo, chrStyle){
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
if(findWhat)app.findGrepPreferences.findWhat = findWhat;
if(fontStyle)app.findGrepPreferences.fontStyle = fontStyle;
// if(position)app.findGrepPreferences.postion = Position.SUPERSCRIPT;
if(fillColor)app.findGrepPreferences.fillColor = fillColor;
if(changeTo)app.changeGrepPreferences.changeTo = changeTo;
if(chrStyle)app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyleGroups.item("03_BodText").characterStyles.item(chrStyle);
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
};
Copy link to clipboard
Copied
Hey,
Use the following code:
replaceTextByFont ("mam", "man");
replaceTextByStyle ("mam", "man");
function replaceTextByStyle (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("SampleFindStyle");
app.changeTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("SampleReplaceStyle");
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
function replaceTextByFont (input, output)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = input;
app.findTextPreferences.appliedFont = app.fonts.item("Arial Bold");
app.changeTextPreferences.appliedFont = app.fonts.item("Arial BoldItalic");
app.changeTextPreferences.changeTo = output;
app.activeDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
Regards,
Ramkumar .P
Copy link to clipboard
Copied
Hey Ramkumar!
I think it's not good idea to change applied font because it will override applied paragraph/character style. Also, "Arial Bold" needs to be "Arial\tBold" and "Arial BoldItalic" needs to be "Arial\tBold Italic". You need "\t" because it separates font family name and font style.
--
tomaxxi
http://indisnip.wordpress.com/
Copy link to clipboard
Copied
Hi Ramkumar,
Please help me, how to find superscript? My complete script is here:
replace ("(.+)", "Italic", "", "SRF Cyan", "", "SRF_it");
replace ("(.+)", "Italic", "", "", "", "_it");
replace ("(.+)", "Bold", "", "SRF Cyan", "", "SRF_bld");
replace ("(.+)", "Bold", "", "", "", "_bld");
//replace ("(.+)", "", "position", "", "_^$1", "");
//replace ("", "", "", "", "", "");
function replace(findWhat, fontStyle, position, fillColor, changeTo, chrStyle){
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
if(findWhat)app.findGrepPreferences.findWhat = findWhat;
if(fontStyle)app.findGrepPreferences.fontStyle = fontStyle;
// if(position)app.findGrepPreferences.postion = Position.SUPERSCRIPT;
if(fillColor)app.findGrepPreferences.fillColor = fillColor;
if(changeTo)app.changeGrepPreferences.changeTo = changeTo;
if(chrStyle)app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyleGroups.item("03_BodText").characterStyles.item(chrStyle);
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
};
Regards,
Sumit
Copy link to clipboard
Copied
Hi,
It is very useful but it doesn't work in CS6? Help!
Thanks
cy
Find more inspiration, events, and resources on the new Adobe Community
Explore Now