8 Replies Latest reply on Jul 22, 2014 4:38 AM by Johnwhite

    Can you correct my unfunction my script?

    Johnwhite Level 1

      Hi, everyone

       

      I made a script for add a continued at end of paragraph but unfunction, call you please help to fix it?

       

      var myDialog = app.dialogs.add({name:"add continueds",canCancel:true});
      with(myDialog){
          with(dialogColumns.add()){
              with(dialogRows.add()){
                 var mySelection = dropdowns.add({stringList:["Continued", "continued", "Cont'd","cont'd"], selectedIndex:0});
             }
         }
      }


      if (myDialog.show() == true)
         
      main();
      function main(){
      var myObject;
      var myCheckSelection = false;
      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 "Text":
          case "Cell":
          case "Column":
          case "Row":
          case "Table":
           myObject = app.selection[0];
           if(myObject != "None")
         }
        }
      }
      else{
        alert("No documents are open. Please open a document and try again.");
      }
      }
      function addContinueds(){
          if (mySelection.selectedIndex == 0){
         app.findGrepPreferences.findWhat = "(.)\\r";
         app.changeGrepPreferences.changeTo = "$1 (Continued)\\r";
         app.selection[0].changeGrep();
         app.findGrepPreferences = app.changeGrepPreferences = null;
          }
          if (mySelection.selectedIndex == 1){
         app.findGrepPreferences.findWhat = "(.)\\r";
         app.changeGrepPreferences.changeTo = "$1 (continued)\\r";
         app.selection[0].changeGrep();
         app.findGrepPreferences = app.changeGrepPreferences = null;
          }
         if (mySelection.selectedIndex == 2){
         app.findGrepPreferences.findWhat = "(.)\\r";
         app.changeGrepPreferences.changeTo = "$1 (Cont'd)\\r";
         app.selection[0].changeGrep();
         app.findGrepPreferences = app.changeGrepPreferences = null;
          }
        if (mySelection.selectedIndex == 3){
         app.findGrepPreferences.findWhat = "(.)\\r";
         app.changeGrepPreferences.changeTo = "$1 (cont'd)\\r";
         app.selection[0].changeGrep();
         app.findGrepPreferences = app.changeGrepPreferences = null;
          }
      }

       

      John

        • 1. Re: Can you correct my unfunction my script?
          Jump_Over Level 5

          Hi John,

           

          You wrote a function addContinueds() but you did not call it.

          Your main function could look like this:

          function main(){
            if(app.selection && app.selection[0].hasOwnProperty ("contents") )
                 addContinueds();
            else alert("No documents are open or wrong selection. Please try again.");
          }
          
          
          

           

          Jarek

          • 2. Re: Can you correct my unfunction my script?
            Johnwhite Level 1

            Hi Jarek

             

            I try to change it into this:

             

            var myDialog = app.dialogs.add({name:"add continueds",canCancel:true});
            with(myDialog){
                with(dialogColumns.add()){
                    with(dialogRows.add()){
                       var mySelection = dropdowns.add({stringList:["Continued", "continued", "Cont'd","cont'd"], selectedIndex:0});
                   }
               }
            }


            if (myDialog.show() == true)
               
            main();
            function main(){
            var myObject;
            var myCheckSelection = false;
            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 "Text":
                case "Cell":
                case "Column":
                case "Row":
                case "Table":
                 myObject = app.selection[0];
                 if(myObject != "None")
               }
              }
            }
            else{
              alert("No documents are open. Please open a document and try again.");
            }
            }
            function main(){ 
            if(app.selection && app.selection[0].hasOwnProperty ("contents") ) 
                   addContinueds(); 
              else alert("No documents are open or wrong selection. Please try again."); 

                if (mySelection.selectedIndex == 0){
               app.findGrepPreferences.findWhat = "(.)\\r";
               app.changeGrepPreferences.changeTo = "$1 (Continued)\\r";
               app.selection[0].changeGrep();
               app.findGrepPreferences = app.changeGrepPreferences = null;
                }
                if (mySelection.selectedIndex == 1){
               app.findGrepPreferences.findWhat = "(.)\\r";
               app.changeGrepPreferences.changeTo = "$1 (continued)\\r";
               app.selection[0].changeGrep();
               app.findGrepPreferences = app.changeGrepPreferences = null;
                }
               if (mySelection.selectedIndex == 2){
               app.findGrepPreferences.findWhat = "(.)\\r";
               app.changeGrepPreferences.changeTo = "$1 (Cont'd)\\r";
               app.selection[0].changeGrep();
               app.findGrepPreferences = app.changeGrepPreferences = null;
                }
              if (mySelection.selectedIndex == 3){
               app.findGrepPreferences.findWhat = "(.)\\r";
               app.changeGrepPreferences.changeTo = "$1 (cont'd)\\r";
               app.selection[0].changeGrep();
               app.findGrepPreferences = app.changeGrepPreferences = null;
                }
            }

             

            but still got an error, source code: addContinueds();

            • 3. Re: Re: Can you correct my unfunction my script?
              Jump_Over Level 5

              Hi,

               

              Watch your copy...paste moves while creating this code.

              A structure suppose to be like:

              //... this is the start of script's job
              var myDialog =
              //... dialog code
                  if (myDialog.show() == true)
                        main();
              //... this is the end of script's job
              
              
              function main() {
                   //... function code
                   //...
                   }
              
              function addContinueds() {
                   //... function code
                   //...
                   }
              
              


              Jarek


              PS. I replaced your main() function with mine in previous post.

              • 4. Re: Can you correct my unfunction my script?
                Johnwhite Level 1

                Thanks Jarek,

                 

                now working

                 

                thank you very much

                 

                John

                • 5. Re: Can you correct my unfunction my script?
                  Johnwhite Level 1

                  Hi, Jarek,

                   

                  I made this script:

                   

                  var myDialog = app.dialogs.add({name:"add continueds",canCancel:true});
                  with(myDialog){
                      with(dialogColumns.add()){
                          with(dialogRows.add()){
                             var mySelection = dropdowns.add({stringList:["Continued", "continued", "Cont'd","cont'd"], selectedIndex:0});
                         }
                     }
                  }


                  if (myDialog.show() == true)
                     
                  main();
                  function main(){
                  var myObject;
                  var myCheckSelection = false;
                  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 "Text":
                      case "Cell":
                      case "Column":
                      case "Row":
                      case "Table":
                       myObject = app.selection[0];
                    if(app.selection && app.selection[0].hasOwnProperty ("contents") );
                        addContinueds(); 
                      }
                    }
                  }
                  else{
                    alert("No documents are open or wrong selection. Please try again.");
                  }
                  }
                  function addContinueds() { 
                      if (mySelection.selectedIndex == 0){
                     app.findGrepPreferences.findWhat = "(.)\\r";
                     app.changeGrepPreferences.changeTo = "$1 (Continued)\\r";
                     app.selection[0].changeGrep();
                     app.findGrepPreferences = app.changeGrepPreferences = null;
                      }
                      if (mySelection.selectedIndex == 1){
                     app.findGrepPreferences.findWhat = "(.)\\r";
                     app.changeGrepPreferences.changeTo = "$1 (continued)\\r";
                     app.selection[0].changeGrep();
                     app.findGrepPreferences = app.changeGrepPreferences = null;
                      }
                     if (mySelection.selectedIndex == 2){
                     app.findGrepPreferences.findWhat = "(.)\\r";
                     app.changeGrepPreferences.changeTo = "$1 (Cont'd)\\r";
                     app.selection[0].changeGrep();
                     app.findGrepPreferences = app.changeGrepPreferences = null;
                      }
                    if (mySelection.selectedIndex == 3){
                     app.findGrepPreferences.findWhat = "(.)\\r";
                     app.changeGrepPreferences.changeTo = "$1 (cont'd)\\r";
                     app.selection[0].changeGrep();
                     app.findGrepPreferences = app.changeGrepPreferences = null;
                      }
                  }

                   

                  as you taught me,

                   

                  but how can I, make a recall function to dropdown list?

                   

                  like it it can repeat my last selected

                   

                  thanks

                   

                  Best regard

                   

                  John

                  • 6. Re: Re: Can you correct my unfunction my script?
                    Jump_Over Level 5

                    Hi,

                     

                    I told about something like this, actually:

                    #target indesign
                    
                    var
                      mySelected = Number( app.extractLabel("mDialog") ),     //     previous selection's set
                      myDialog = app.dialogs.add({name:"add continueds",canCancel:true});
                      if ( isNaN( mySelected ) ) mySelected = 0;
                    
                      with(myDialog){
                           with(dialogColumns.add()){
                                with(dialogRows.add()){
                                     var
                                     mySelection = dropdowns.add({stringList:["Continued", "continued", "Cont'd","cont'd"], selectedIndex: mySelected});
                                }
                           }
                      }
                    
                    
                    if (myDialog.show() == true)
                        main();
                    myDialog.destroy();
                    
                    
                    function main(){
                      mySelected = app.insertLabel( "mDialog", String(mySelection.selectedIndex) );     //     to remember selection's set
                      if(app.selection.length && app.selection[0].hasOwnProperty ("contents") ) addContinueds(); 
                      else alert("Wrong selection. Please try again.");
                    }
                    function addContinueds() { 
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      switch (mySelection.selectedIndex){
                           case 1: app.changeGrepPreferences.changeTo = "$1 (continued)";
                                break;
                           case 2: app.changeGrepPreferences.changeTo = "$1 (Cont'd)";
                                break;
                           case 3: app.changeGrepPreferences.changeTo = "$1 (cont'd)";
                                break;
                           default: app.changeGrepPreferences.changeTo = "$1 (Continued)";
                                break;
                           }
                      app.findGrepPreferences.findWhat = "(.)$";
                      app.selection[0].paragraphs[-1].changeGrep();     // NOTICE: the last paragraph of selection is targeted
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                    }
                    

                     

                    There is app.insertLabel() used for keeping previous selection index

                     

                    Jarek

                    • 7. Re: Can you correct my unfunction my script?
                      Johnwhite Level 1

                      Thank you Jarek,

                       

                      Thank you very much, it's so complicate, I thank I can't find a solution to make it happen by myself,

                       

                      so thank you so much

                       

                      John

                      • 8. Re: Can you correct my unfunction my script?
                        Johnwhite Level 1

                        Hi, Jarek

                         

                        I change it into this format (for in case of find-change two or more items) but not work: ---- why?

                         

                        var

                          mySelected = Number( app.extractLabel("mDialog") ),     //     previous selection's set

                          myDialog = app.dialogs.add({name:"add continueds",canCancel:true});

                          if ( isNaN( mySelected ) ) mySelected = 0;

                         

                          with(myDialog){

                               with(dialogColumns.add()){

                                    with(dialogRows.add()){

                                         var

                                         mySelection = dropdowns.add({stringList:["01   Continued", "02   continued", "03   Cont'd","04   cont'd"], selectedIndex: mySelected});

                                    }

                               }

                          }

                         

                         

                        if (myDialog.show() == true)

                            main();

                        myDialog.destroy();

                         

                         

                        function main(){

                          mySelected = app.insertLabel( "mDialog", String(mySelection.selectedIndex) );     //     to remember selection's set

                          if(app.selection.length && app.selection[0].hasOwnProperty ("contents") ) addContinueds(); 

                          else alert("Wrong selection. Please try again.");

                        }

                        function addContinueds() { 

                          app.findGrepPreferences = app.changeGrepPreferences = null;

                          switch (mySelection.selectedIndex){

                               case 1:

                          app.findGrepPreferences.findWhat = "(.)\\r";

                          app.selection[0].changeGrep();

                          app.changeGrepPreferences.changeTo = "$1 (continued)\\r";

                          app.findGrepPreferences = app.changeGrepPreferences = null;

                                    break;

                               case 2:

                          app.findGrepPreferences.findWhat = "(.)\\r";

                          app.selection[0].changeGrep();

                          app.changeGrepPreferences.changeTo = "$1 (Cont'd)\\r";

                          app.findGrepPreferences = app.changeGrepPreferences = null;

                                    break;

                               case 3:

                          app.findGrepPreferences.findWhat = "(.)\\r";

                          app.selection[0].changeGrep();

                          app.changeGrepPreferences.changeTo = "$1 (cont'd)\\r";

                          app.findGrepPreferences = app.changeGrepPreferences = null;

                                    break;

                            default:

                          app.findGrepPreferences.findWhat = "(.)\\r";

                          app.selection[0].changeGrep();

                          app.changeGrepPreferences.changeTo = "$1 (Continued)\\r";

                          app.findGrepPreferences = app.changeGrepPreferences = null;

                                    break;

                               }

                        }