16 Replies Latest reply on Dec 12, 2013 11:53 AM by creativejoan0425

    javascript: select all text, break link to style

    Digital-junkie

      Hi

       

      I'd like to select all text in a Document (in different independent textboxes) and then break the link to it's style (in the program in the Flyout-menu of the paragraph styles)

       

      Is this function scriptable (javascript)?

      How do I select all the text?

       

      InDesign CS6, OS10.7.4

       

      Thanks

        • 1. Re: javascript: select all text, break link to style
          Jump_Over Level 5

          Hi,

           

          app.activeDocument.stories.everyItem().texts.everyItem().applyParagraphStyle(app.activeDoc ument.paragraphStyles.item(0), false);     // this should apply [None] paraStyle and keep formats; the same with charStyles.

           

          Your goal will be reached except some formats set using NestedStyle info paraStyle definition (GREP, NestedLineStyle)

          ==>those disappear, I am afraid.

          hope...

          • 2. Re: javascript: select all text, break link to style
            Digital-junkie Level 1

            Works perfectly (even with a nested style), thanks!

            • 3. Re: javascript: select all text, break link to style
              MadMac55 Level 1

              What'd the script look like in its entirety?

              • 4. Re: javascript: select all text, break link to style
                Digital-junkie Level 1

                All you need is the line Jump_Over has written (app.active…)

                • 5. Re: javascript: select all text, break link to style
                  camilo umaña Level 1

                  The script (now called vanilla) is giving an error:

                   

                   

                  Screen Shot 2013-06-21 at 5.25.45 AM.jpg

                  • 6. Re: javascript: select all text, break link to style
                    Larry G. Schneider Adobe Community Professional & MVP

                    Somehow a space gets inserted into (.applyParagrap hStyle) when you copy/paste the line from the website. Just delete it.

                    • 7. Re: javascript: select all text, break link to style
                      creativejoan0425 Level 1

                      I try to use the script, but it doesn't work in table, table's text still have paragraph style, how can also break link to style in table?

                      • 8. Re: javascript: select all text, break link to style
                        Digital-junkie Level 1

                        try this

                        (probably not the most efficient way, but it worked)

                         

                        ––––

                         

                        #target InDesign

                         

                        /* Breaks links to style for character and paragraph styles */

                         

                        //prepare Undo

                            app.doScript(createInlineText, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Break Link to Style");        

                         

                         

                        function createInlineText() {

                         

                        app.activeDocument.stories.everyItem().texts.everyItem().applyParagraphStyle(app.activeDoc ument.paragraphStyles.item(0), false);

                        app.activeDocument.stories.everyItem().texts.everyItem().applyCharacterStyle(app.activeDoc ument.characterStyles.item(0), false);

                        myTables = app.activeDocument.stories.everyItem().tables.everyItem();

                        myTables.cells.everyItem().paragraphs.everyItem().applyParagraphStyle(app.activeDocument.p aragraphStyles.item(0), false);

                        myTables.cells.everyItem().paragraphs.everyItem().applyCharacterStyle(app.activeDocument.c haracterStyles.item(0), false);

                        }  

                        • 10. Re: javascript: select all text, break link to style
                          creativejoan0425 Level 1

                          Sorry, one more question, it I want to do it in a selection?

                          • 11. Re: javascript: select all text, break link to style
                            Digital-junkie Level 1

                            why do you need a script for this?

                            just click "Break Link to Style" in the flyout-menu of the paragraph/character styles

                            • 12. Re: javascript: select all text, break link to style
                              creativejoan0425 Level 1

                              In fact, I use the adobe findchangebylist to modified, I want to do a clear setting script, not only break link to style, but when i run the script that will get error, can u help me to fix it, my script is shown as below:

                               

                              main();
                              function main(){
                              var myObject;
                              //var myCheckSelection = false;
                              //Make certain that user interaction (display of dialogs, etc.) is turned on.
                              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                              if(app.documents.length > 0){
                                if(app.selection.length > 0){
                                 switch(app.selection[0].constructor.name){
                                  case "InsertionPoint":
                                  case "Character":
                                  case "Word":
                                  case "TextStyleRange":
                                  case "Line":
                                  case "Paragraph":
                                  case "TextColumn":
                                  case "TextFrame":
                                  case "Text":
                                  case "Cell":
                                  case "Column":
                                  case "Row":
                                  case "Table":
                                   myDisplayDialog();

                                   break;
                                  default:
                                   //Something was selected, but it wasn't a text object, so search the document.
                                   //myFindChangeByList(app.documents.item(0));
                                                  //alert("Nothing Selected, Please Select Text Frame or Text.");
                                 }
                                }

                                else{
                                 //Nothing was selected, so simply search the document.
                                          //myFindChangeByList(app.documents.item(0));
                                          alert("Nothing Selected, Please Select Text Frame or Text.");
                                }
                              }
                              else{
                                alert("No documents are open. Please open a document and try again.");
                              }
                              }
                              function myDisplayDialog(){
                              var myObject;
                              var myDialog = app.dialogs.add({name:"Joan New Clear Setting_v1.0"});
                              with(myDialog.dialogColumns.add()){
                                 with(dialogRows.add()){
                                 with(dialogColumns.add()){
                              staticTexts.add({staticLabel:"Search Range:"});
                                   var mySearchButtons = radiobuttonGroups.add();
                                   with(mySearchButtons){
                                   radiobuttonControls.add({staticLabel:"Current Document", checkedState:true});
                                                 if(app.selection[0].contents != ""){
                                  radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
                                              }
                                   }
                                  }
                                 with(dialogColumns.add()){
                                  with(borderPanels.add()){
                                   staticTexts.add({staticLabel:"Clear Setting:"});
                                   var myDateButtons = radiobuttonGroups.add();
                                   with(myDateButtons){
                                   radiobuttonControls.add({staticLabel:"English", checkedState:true});
                                   radiobuttonControls.add({staticLabel:"Chinese"});
                                    }
                                  }
                                 }
                                }
                               
                              }

                              var myResult = myDialog.show();
                              if(myResult == true){
                                switch(mySearchButtons.selectedButton){
                                 case 0:
                                               BreakLinktoStyleDocument();
                                               TurnOffHyphenationDocument();
                                               myObject = app.documents.item(0);
                                               myCheckSelection = false;
                                  break;
                                            case 1:
                                               BreakLinktoStyleSelection();
                                               TurnOffHyphenationSelection();
                                               myObject = app.selection[0];
                                               myCheckSelection = true;

                                  break;
                                }
                                switch(myDateButtons.selectedButton){
                                case 0:
                                myFindChangeByList1(myObject, myCheckSelection);
                                               
                                break;
                                case 1:
                                myFindChangeByList2(myObject, myCheckSelection);
                                break;
                                 }
                                myDialog.destroy();
                                //myFindChangeByList1(myObject);
                              }
                              else{
                                myDialog.destroy();
                              }
                              }
                              //---------------------------------------------------------------------------------------- ---------
                              function TurnOffHyphenationDocument() {
                              app.activeDocument.stories.everyItem().texts.everyItem().hyphenation=false;
                              myTables = app.activeDocument.stories.everyItem().tables.everyItem();
                              myTables.cells.everyItem().paragraphs.everyItem().hyphenation=false;
                              }

                              function TurnOffHyphenationSelection() {
                              app.selection[0].texts[0].hyphenation=false;
                              app.selection[0].cells.everyItem().texts[0].hyphenation=false;
                              }

                              //---------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------ --------------
                              function BreakLinktoStyleDocument() {
                              app.activeDocument.stories.everyItem().texts.everyItem().applyParagraphStyle(app.activeDoc ument.paragraphStyles.item(0), false);
                              app.activeDocument.stories.everyItem().texts.everyItem().applyCharacterStyle(app.activeDoc ument.characterStyles.item(0), false);
                              myTables = app.activeDocument.stories.everyItem().tables.everyItem();
                              myTables.cells.everyItem().paragraphs.everyItem().applyParagraphStyle( app.activeDocument.paragraphStyles.item(0), false);
                              myTables.cells.everyItem().paragraphs.everyItem().applyCharacterStyle( app.activeDocument.characterStyles.item(0), false);
                              }

                              function BreakLinktoStyleSelection() {
                              app.selection[0].texts.everyItem().applyParagraphStyle(app.activeDocument.paragraphStyles. item(0), false);
                              app.selection[0].texts.everyItem().applyCharacterStyle(app.activeDocument.characterStyles. item(0), false);
                              app.selection[0].cells.everyItem().texts[0].applyParagraphStyle(app.activeDocument.paragra phStyles.item(0), false);
                              app.selection[0].cells.everyItem().texts[0].applyCharacterStyle(app.activeDocument.charact erStyles.item(0), false);
                              }

                              //---------------------------------------------------------------------------------------- ----------
                              function myFindChangeByList1(myObject, myCheckSelection){
                              var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
                              var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit;
                              var myStartCharacter, myEndCharacter;
                              var myFindChangeFile = myFindFile("/ScriptSupport/te.txt")
                              if(myFindChangeFile != null){
                                      // Because the selection will change as we add/remove characters,
                                      // we'll need to reset the selection after each pass if we are
                                      // checking the selection. We'll get the index of the first character
                                      // in the selection (relative to the start of its parent story) and
                                      // the index of the last character in the selection (relative to the
                                      // *end* of the story, and we'll use them later in the script to
                                      // keep the ends of the selection in place.
                                if(myCheckSelection == true){
                                 var myStart = myObject.characters.item(0).index;
                                 var myEnd = myObject.characters.item(-1).index;
                                 var myStory = myObject.parentStory;
                                 var myStoryEnd = myStory.characters.item(-1).index;
                                 myEnd = (myStoryEnd - myEnd)+1;
                                }
                                myFindChangeFile = File(myFindChangeFile);
                                var myResult = myFindChangeFile.open("r", undefined, undefined);
                                if(myResult == true){
                                 //Loop through the find/change operations.
                                 do{
                                  myLine = myFindChangeFile.readln();
                                  //Ignore comment lines and blank lines.
                                  if((myLine.substring(0,4)!="text")||(myLine.substring(0,4)!="grep")||(myLine.substring(0, 5)!="glyph")){
                                   myFindChangeArray = myLine.split("\t");
                                   //The first field in the line is the findType string.
                                   myFindType = myFindChangeArray[0];
                                   //The second field in the line is the FindPreferences string.
                                   myFindPreferences = myFindChangeArray[1];
                                   //The second field in the line is the ChangePreferences string.
                                   myChangePreferences = myFindChangeArray[2];
                                   //The fourth field is the range--used only by text find/change.
                                   myFindChangeOptions = myFindChangeArray[3];
                                   switch(myFindType){
                                    case "text":
                                     myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                     break;
                                    case "grep":
                                     myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                     break;
                                    case "glyph":
                                     myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                     break;
                                   }
                                   if(myCheckSelection == true){
                                    myStartCharacter = myStory.characters.item(myStart);
                                    myEndCharacter = myStory.characters.item(-myEnd);
                                    myObject = myStory.texts.itemByRange(myStartCharacter, myEndCharacter);
                                    app.select (myObject);
                                   }
                                  }
                                 } while(myFindChangeFile.eof == false);
                                 myFindChangeFile.close();
                                }
                              }
                              alert("Done");
                              }
                              function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                              //Reset the find/change preferences before each search.
                              app.changeTextPreferences = NothingEnum.nothing;
                              app.findTextPreferences = NothingEnum.nothing;
                              app.findChangeTextOptions = NothingEnum.nothing;
                              var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
                              myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
                              myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
                              app.doScript(myString, ScriptLanguage.javascript);
                                myFoundItems = myObject.changeText();
                              //Reset the find/change preferences after each search.
                              app.changeTextPreferences = NothingEnum.nothing;
                              app.findTextPreferences = NothingEnum.nothing;
                              app.findChangeTextOptions = NothingEnum.nothing;
                              }
                              function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                              //Reset the find/change grep preferences before each search.
                              app.changeGrepPreferences = NothingEnum.nothing;
                              app.findGrepPreferences = NothingEnum.nothing;
                              app.findChangeGrepOptions = NothingEnum.nothing;
                              var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
                              myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
                              myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
                              app.doScript(myString, ScriptLanguage.javascript);
                              var myFoundItems = myObject.changeGrep();
                              //Reset the find/change grep preferences after each search.
                              app.changeGrepPreferences = NothingEnum.nothing;
                              app.findGrepPreferences = NothingEnum.nothing;
                              app.findChangeGrepOptions = NothingEnum.nothing;
                              }
                              function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                              //Reset the find/change glyph preferences before each search.
                              app.changeGlyphPreferences = NothingEnum.nothing;
                              app.findGlyphPreferences = NothingEnum.nothing;
                              app.findChangeGlyphOptions = NothingEnum.nothing;
                              var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
                              myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
                              myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
                              app.doScript(myString, ScriptLanguage.javascript);
                              var myFoundItems = myObject.changeGlyph();
                              //Reset the find/change glyph preferences after each search.
                              app.changeGlyphPreferences = NothingEnum.nothing;
                              app.findGlyphPreferences = NothingEnum.nothing;
                              app.findChangeGlyphOptions = NothingEnum.nothing;
                              }
                              function myFindFile(myFilePath){
                              var myScriptFile = myGetScriptPath();
                              var myScriptFile = File(myScriptFile);
                              var myScriptFolder = myScriptFile.path;
                              myFilePath = myScriptFolder + myFilePath;
                              if(File(myFilePath).exists == false){
                                //Display a dialog.
                                myFilePath = File.openDialog("Choose the file containing your find/change list");
                              }
                              return myFilePath;
                              }
                              function myGetScriptPath(){
                              try{
                                myFile = app.activeScript;
                              }
                              catch(myError){
                                myFile = myError.fileName;
                              }
                              return myFile;
                              }

                               

                              and here is my text file, te.txt

                               

                              //001

                              grep {findWhat:"."} {appliedLanguage: app.languagesWithVendors.item("English: USA"), kerningMethod: "無"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //002

                              grep {findWhat:"."} {kinsokuSet: "繁體中文避頭尾(s)"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //003

                              grep {findWhat:"."} {mojikumi: "nothing"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //004

                              grep {findWhat:"."} {ligatures:false} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //005

                              grep {findWhat:"."} {gridAlignment: 1852796517} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //006

                              grep {findWhat:"."} {leadingModel: 1248619858} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              //007

                              grep {findWhat:"."} {characterAlignment: 1247896172} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, includeLockedStoriesForFind:true, widthSensitive:true}

                              • 13. Re: javascript: select all text, break link to style
                                creativejoan0425 Level 1

                                Hi I try Break link to Style for also cells and tables in current document by using the script that u last time gave me, but it seem error

                                 

                                /* Breaks links to style for character and paragraph styles */

                                 

                                //prepare Undo

                                    app.doScript(createInlineText, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Break Link to Style");        

                                 

                                 

                                function createInlineText() {

                                 

                                app.activeDocument.stories.everyItem().texts.everyItem().applyParagrap hStyle(app.activeDocument.paragraphStyles.item(0), false);

                                app.activeDocument.stories.everyItem().texts.everyItem().applyCharacte rStyle(app.activeDocument.characterStyles.item(0), false);

                                myTables = app.activeDocument.stories.everyItem().tables.everyItem();

                                myTables.cells.everyItem().paragraphs.everyItem().applyParagraphStyle( app.activeDocument.paragraphStyles.item(0), false);

                                myTables.cells.everyItem().paragraphs.everyItem().applyCharacterStyle( app.activeDocument.characterStyles.item(0), false);

                                myTables.cells.everyItem().applyCellStyle( app.activeDocument.cellStyles.item(0), false);

                                myTables.applyTableStyle( app.activeDocument.tableStyles.item(0), false);

                                }  

                                • 14. Re: javascript: select all text, break link to style
                                  Digital-junkie Level 1

                                  There is no method applyTableStyle

                                  One can apply formats with the properties Table.appliedTableStyle/Cell.appliedCellStyle

                                   

                                  Here is an exemple:

                                   

                                  // _____

                                   

                                  //prepare Undo

                                  app.doScript(createInlineText, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Break Link to TableStyle");

                                   

                                  function createInlineText() {

                                   

                                      var myDoc = app.activeDocument;

                                   

                                      myTables = myDoc.stories.everyItem().tables.everyItem().getElements();

                                      for ( var i = 0; i < myTables.length; i++) {

                                          myTable = myTables[i];

                                          myTable.appliedTableStyle = myDoc.tableStyles.item(0), false;

                                           }

                                  }

                                  • 15. Re: javascript: select all text, break link to style
                                    creativejoan0425 Level 1

                                    If do it in selection?

                                     

                                    Is it just chang var myDoc = app.activeDocument to app.selection[0]?

                                     

                                     

                                    從三星手機發送

                                    • 16. Re: javascript: select all text, break link to style
                                      creativejoan0425 Level 1

                                      I just discover that i cant change in empty cell how can fix it?

                                       

                                       

                                      從三星手機發送