Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple example: find / replace text?

New Here ,
Mar 16, 2008 Mar 16, 2008
Hi,

I was looking for a simple sample to show opening a document, search for some text (e.g. brett) and replace with new text(e.g Brett1), then close the document.

Is there any examples out there on how to do this? The scripting samples that come with the documentation don't cover this simple task I believe.

Many thanks,

Brett
TOPICS
Scripting
740
Translate
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 Expert ,
Mar 16, 2008 Mar 16, 2008
Which InDesign version?

Peter
Translate
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
New Here ,
Mar 16, 2008 Mar 16, 2008
InDesign Server CS3
Translate
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 Expert ,
Mar 16, 2008 Mar 16, 2008
app.open (File ('/d/test.indd'));
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = 'Brett';
app.changeTextPreferences.changeTo = 'Peter';
app.activeDocument.changeText();
app.activeDocument.save();
app.activeDocument.close();

Then there are several options (for case-sensitivity, whole-word only, etc.) -- see the documentation.

Peter
Translate
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
New Here ,
Mar 17, 2008 Mar 17, 2008
Thank you..

This app.activeDocument, isn't that more for scripting the desktop version not the server?
Translate
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 Expert ,
Mar 17, 2008 Mar 17, 2008
I've no idea.

Peter
Translate
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
Explorer ,
Mar 17, 2008 Mar 17, 2008
Hi Brett,

In InDesign Server, that's:

app.documents.item(0)

There's an example of this in the Text chapter of the CS3 Scripting Guide. If you're using CS2, it's different.

Thanks,

Ole
Translate
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
New Here ,
Mar 17, 2008 Mar 17, 2008
LATEST
Thank you all so much. It means a lot to get your help.

It worked with this, not sure if its the right thing / best practice ??

myInDesignServer = CreateObject("COM", "InDesignServer.Application.CS3");

myDocument = myInDesignServer.Open("c:\b.indd");

// app.changeTextPreferences = null;
// app.findTextPreferences = app.changeTextPreferences;

myInDesignServer.findTextPreferences.findWhat = "brett";
myInDesignServer.changeTextPreferences.changeTo = "Peter";
myInDesignServer.changeText();

myDocument.Save("c:\b.indd");
myDocument.close();
Translate
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