Copy link to clipboard
Copied
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;
}
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks mate
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now