6 Replies Latest reply on Jan 27, 2009 7:09 AM by (Andrew_Alcantara)

    [AS][CS3] Finding text with character style

    (Andrew_Alcantara)
      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
        • 1. Re: [AS][CS3] Finding text with character style
          Level 1
          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
          • 2. Re: [AS][CS3] Finding text with character style
            sstanleyau Level 4
            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>
            • 3. Re: [AS][CS3] Finding text with character style
              Level 1
              Ah, I failed to spot the AS in the topic.

              Dave
              • 4. Re: [AS][CS3] Finding text with character style
                (Andrew_Alcantara) Level 1
                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
                • 5. Re: [AS][CS3] Finding text with character style
                  sstanleyau Level 4
                  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>
                  • 6. Re: [AS][CS3] Finding text with character style
                    (Andrew_Alcantara) Level 1
                    Thanks for your help, it is all working now.

                    Regards,

                    Andrew