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

[AS][CS3] Finding text with character style

New Here ,
Jan 26, 2009 Jan 26, 2009

Copy link to clipboard

Copied

Please help to tell me how to find text with a specific character style and then delete the text.

I had no problem doing this with CS2 but its doing my head in now.

Thanks,

Andrew
TOPICS
Scripting

Views

605

Translate

Translate

Report

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
Participant ,
Jan 26, 2009 Jan 26, 2009

Copy link to clipboard

Copied

Here you go. This assumes that your character style is at the top level of the panel. If you're using style groups, you'll need to write code to get at the style you want to use.
//DESCRIPTION: Delete text in named character style


(function() {
if (app.documents.length > 0) {
deleteStyledText(app.documents[0]);
}
function deleteStyledText(aDoc) {
var cStyle = aDoc.characterStyles.item("CharStyleName");
setupFindText();
app.findTextPreferences.appliedCharacterStyle = cStyle;
aDoc.changeText();
}
function setupFindText(find, change, wholeWd, caseSense, foots, hidLayers, lockedLayers, lockedStories, masters) {
app.findTextPreferences = null;
app.changeTextPreferences = null;
try { app.findTextPreferences.findWhat = find } catch(e) {};
try {app.changeTextPreferences.changeTo = change } catch(e) {};
app.findChangeTextOptions.properties = {
caseSensitive:(caseSense == null ? false : caseSense),
wholeWord:(wholeWd == null ? false : wholeWd),
includeFootnotes:(foots == null ? false : foots),
includeHiddenLayers:(hidLayers == null ? false : hidLayers),
includeLockedLayersForFind:(lockedLayers == null ? false : lockedLayers),
includeLockedStoriesForFind:(lockedStories == null ? false : lockedStories),
includeMasterPages:(masters == null ? false : masters)
}
} // end setupFindText
}())
Dave

Votes

Translate

Translate

Report

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
Advocate ,
Jan 26, 2009 Jan 26, 2009

Copy link to clipboard

Copied

You could try this:<br /><br />tell application "Adobe InDesign CS3"<br /> tell document 1<br /> set thestyle to character style "Whatever"<br /> delete (every text style range of every story whose applied<br />character style is thestyle)<br /> end tell<br />end tell<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>

Votes

Translate

Translate

Report

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
Participant ,
Jan 26, 2009 Jan 26, 2009

Copy link to clipboard

Copied

Ah, I failed to spot the AS in the topic.

Dave

Votes

Translate

Translate

Report

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 ,
Jan 27, 2009 Jan 27, 2009

Copy link to clipboard

Copied

Thank you to the both of you. However this is still giving me error "CS3 got an error. Can't set character style of find text preferences to character style ID of document"
I have tried changing things around but still get the same error.

Appreciate your help,

Regards,

Andrew

Votes

Translate

Translate

Report

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
Advocate ,
Jan 27, 2009 Jan 27, 2009

Copy link to clipboard

Copied

If you want to do the search using the find/change commands, you need to<br />make a temporary character style of the same name at the application, use a<br />reference to that style for the search, and then delete it from the app when<br />you're finished.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>

Votes

Translate

Translate

Report

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 ,
Jan 27, 2009 Jan 27, 2009

Copy link to clipboard

Copied

LATEST
Thanks for your help, it is all working now.

Regards,

Andrew

Votes

Translate

Translate

Report

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