Skip to main content
Known Participant
April 14, 2010
Answered

Change Text Preferences

  • April 14, 2010
  • 1 reply
  • 785 views

Hello

I have a method which changes some text in a text frame But I only wish to change the first instance it finds. At the moment it changes all finds.

Is there a Prefernce setting ChangeTextPreference.ButJustTheFirstOneMatey

or equivalent?

Many Thanks

Mark.

Please ignore the C# and 'pretend' it's javascript.

               private void ChangeTextFrameText(Document doc, TextFrame TargetTextFrame, string ChangeText, string ChangeTo)

                {

                    Application IndesignApp = (Application)doc.Parent;

                    IndesignApp.FindTextPreferences = idNothingEnum.idNothing;

                    IndesignApp.ChangeTextPreferences = idNothingEnum.idNothing;

                    FindTextPreference FTP = (FindTextPreference)IndesignApp.FindTextPreferences;

                    FTP.FindWhat = ChangeText;

                    ChangeTextPreference CTP = (ChangeTextPreference)IndesignApp.ChangeTextPreferences;

                    CTP.ChangeTo = ChangeTo;

                    FindChangeTextOption FCTO = (FindChangeTextOption)IndesignApp.FindChangeTextOptions;

                    FCTO.CaseSensitive = false;

                    FCTO.IncludeFootnotes = false;

                    FCTO.IncludeHiddenLayers = false;

                    FCTO.IncludeLockedLayersForFind = false;

                    FCTO.IncludeLockedStoriesForFind = false;

                    FCTO.IncludeMasterPages = false;

                    FCTO.WholeWord = false;

                    Objects O = TargetTextFrame.ParentStory.ChangeText(false);

                    IndesignApp.FindTextPreferences = idNothingEnum.idNothing;

                    IndesignApp.ChangeTextPreferences = idNothingEnum.idNothing;

          }

This topic has been closed for replies.
Correct answer Shonkyin-CF145T

I don't think there is any prefrence like  "ChangeTextPreference.ButJustTheFirstOneMatey"

As per my opinion you replace your code

Objects O = TargetTextFrame.ParentStory.ChangeText(false);

with this

Objects O = TargetTextFrame.ParentStory.FindText();

and you get a list of array in O and then replace O[0] with your output.

Shonky

1 reply

Shonkyin-CF145TCorrect answer
Inspiring
April 14, 2010

I don't think there is any prefrence like  "ChangeTextPreference.ButJustTheFirstOneMatey"

As per my opinion you replace your code

Objects O = TargetTextFrame.ParentStory.ChangeText(false);

with this

Objects O = TargetTextFrame.ParentStory.FindText();

and you get a list of array in O and then replace O[0] with your output.

Shonky

CoullyAuthor
Known Participant
April 15, 2010

Thanks mate

Harbs.
Legend
April 15, 2010

Of course, changing the contents will totally destroy any anchored objects or tables, etc.

It might be better to use:

var textToChange = TargetTextFrame.ParentStory.findText()[0];

if(textToChange){

  textToChange.changeText();

}

Harbs