4 Replies Latest reply on Feb 11, 2013 1:31 PM by Jump_Over

    findTextPreferences

    mrfsrf5

      Hi all,

       

      The more I try to learn about the scripting Indesign,the more I stumble upon a new feature that blows my mind away

      That just happend with "findTextPreferences" feature.

       

      What I'm trying to do is find the text inside table cells that has specific color swatch applied to them and try to manipulate with it, copy it to another textFRame or delete it.

      In this case im trying to find text that has "pink" and "cyan" color applied and remove it altogether.

      here is my code

       

       

      var myDoc = app.activeDocument.stories.everyItem();

      var myColor = doc.swatches.item("Pink");

       

       

      app.findTextPreferences = app.changeTextPreferences = null;

      app.findChangeTextOptions.includeLockedLayersForFind = false;

      app.findChangeTextOptions.includeLockedStoriesForFind = false;

      app.findChangeTextOptions.includeHiddenLayers = false;

      app.findChangeTextOptions.includeMasterPages = false;

      app.findChangeTextOptions.includeFootnotes = true;

      app.findChangeTextOptions.caseSensitive = false;

      app.findChangeTextOptions.wholeWord = true;

       

      //Important

      app.findTextPreferences.fillColor = "Pink";

       

      //I dont know what to put here!!

      replace ("*", "");

       

      function replace (myFind, myReplace) { 

        

      app.findTextPreferences.findWhat = myFind;

      app.changeTextPreferences.changeTo = myReplace;

      app.activeDocument.stories.everyItem( ).tables.everyItem( ).changeText( );

      }

        • 1. Re: findTextPreferences
          mrfsrf5 Level 1

          eh, just as i wrote the question I got the idea and it works

          The solution was to just ommit the findTextPreferences, at least it was one way to solve it.

          But what about if you have the situation where you have to remove text that has !two! colors applied?

           

           

          replace (" ");

           

           

          function replace (myReplace) {

             

          app.changeTextPreferences.changeTo = myReplace;

           

           

          app.activeDocument.stories.everyItem( ).tables.everyItem( ).changeText( );

          }

          • 2. Re: findTextPreferences
            [Jongware] Most Valuable Participant

            First handle all texts with one color applied to it, then the ones with the other color. That's only going to work with your Remove function -- to move it to another frame, you'd need something quite different. Perhaps loop over TextStyleRanges, processing only those with one of your colors.

             

            The reason you can "omit findTextPreferences" in your code is actually straightforward. You don't really omit them (you set all kinds of values in the code above it), but if you only want to find *attributes*, you should leave the findWhat gield empty. Nothing to do with this being a script, as you would do exactly the same in the interface to search for any colored text.

            1 person found this helpful
            • 3. Re: findTextPreferences
              mrfsrf5 Level 1

              Sorry for bringing topic from the dead. I have been fiddling with the textStyleRanges. But unfortunately the tables object doesnt support the textStyleRange method.

              I guess the solution would be to convert the tables to textFrame than apply extStyleRange method, but along the way i loose some possibilities of formmating the text inside cells.

              Is there any other way that you can think of?

              • 4. Re: findTextPreferences
                Jump_Over Level 5

                Hi,

                 

                I am not sure if your goal is to replace those texts in one step?

                If not, try this:

                (after seting all desired findTextPreferences and Options)

                 

                myDoc = app.activeDocument;
                col1 = myDoc.swatches.item("col_1");
                col2 = myDoc.swatches.item("col_2");
                arr = [col1,col2];
                myReplace(myDoc, arr);
                
                function myReplace (obj, arr) {
                    for (k=0; k<arr.length;k++) {
                        app.findTextPreferences.fillColor = arr[k];
                        obj.changeText();
                        }
                    }
                

                 

                rgds

                1 person found this helpful