15 Replies Latest reply on Jan 16, 2011 9:12 PM by Haakenlid

    my Find & replace Dialog

    kerosk_inddNew

      Hi All

       

       

      I am writing a script which can user to allow find, remove and skip dialog.

       

      See my below JS code it is working but I can only get alert message not dialog.

       

      Could anybody please help me out of this. Is it posible it works like a find & replace dialog box.

       

      Please cooperate me.

       

      Thanks,

      Kerosk

       

       

       

       

      myDialog = new Window("dialog", "MyFindDialog");
      myDialog.myFnBtn = myDialog.add("button", undefined, "Find Next");
      myDialog.myFnBtn.onClick = function()
      {
      myDialog.close(0);
      }
      myDialog.myRmBtn = myDialog.add("button", undefined, "Remove");
      myDialog.myRmBtn.onClick = function()
      {
      myDialog.close(1);
      }
      myDialog.mySkBtn = myDialog.add("button", undefined, "Skip");
      myDialog.mySkBtn.onClick = function()
      {
      myDialog.close(2);
      }
      //myDialog.center();
      var myDlg = myDialog.show();
      if(myDlg == 0)
      {   
        EmptyTf= app.activeDocument.layers.item(0).textFrames;

                     for (etf=0; etf<EmptyTf.length; etf++)

                     if (EmptyTf[etf].contents<=0)

                     {

                     app.select(EmptyTf[etf]);
           
          

                     alert ("Selected  is EMPTY Textframe.\r"+"Textframe selected "+[etf]+".");
      }
      }

      else if(myDlg == 1)
      {   
      EmptyTf= app.activeDocument.layers.item(0).textFrames;

                                    for (etf=0; etf<EmptyTf.length; etf++)

                                    if (EmptyTf[etf].contents<=0)

                                         {

                                         app.select(EmptyTf[etf]);

                                         var select=app.selection[etf];

                                          select.remove();

                                         alert ("Selected  is EMPTY Textframe.\r"+"Delete  "+[etf]+".");

                               }
            }
          
           else if(myDlg == 2)
      {   
      EmptyTf= app.activeDocument.layers.item(0).textFrames;

                          for (etf=0; etf<EmptyTf.length; etf++)

                          if (EmptyTf[etf].contents<=0)

                               {

                                    app.select(EmptyTf[etf]);

                                         var select=app.selection[0];

                                         var select=app.selection[etf+1];

                                         alert ("Next"+[etf]+".");

                                    }
              }

        • 1. Re: my Find & replace Dialog
          Harbs. Level 6

          I'm not sure what you are trying to do. Would changing it to "palette" instead of "dialog" and not close it on click help?

           

          Harbs

          • 2. Re: my Find & replace Dialog
            kerosk_inddNew Level 1

            Dear  Harbs,

             

            You are right, I need to use palette.

             

            But I am not getting my target. I just like to used my script as a find and change palette.

             

            What type of change need to be done in my script, could you please help me out.

             

            sincerely  thanking you,

             

            Kerosk.

            • 3. Re: my Find & replace Dialog
              kerosk_inddNew Level 1

              Anyone can help me on this.

              Really, very eager to find a solution.

              • 4. Re: my Find & replace Dialog
                Haakenlid Level 3

                What exactly is the problem?

                 

                Have you tried adding this line to the top of the script?

                #targetengine "session"
                
                • 5. Re: my Find & replace Dialog
                  kerosk_inddNew Level 1

                  Yes, I have tried and it says "cannot execute."

                   

                  Please help if you can.

                  • 6. Re: my Find & replace Dialog
                    Haakenlid Level 3

                    Do you want to run the script from InDesign og EST ?

                    "Session" is a script engine in InDesign. In the script window in EST you must choose "InDesign" from the drop down menu.

                    • 7. Re: my Find & replace Dialog
                      kerosk_inddNew Level 1

                      I tried as you said but it is not working.

                      • 8. Re: my Find & replace Dialog
                        kerosk_inddNew Level 1

                        I want this script to work as a find and replace palette. Like if we find any empty text frame than we have choice to remove or skip the frame. But now its find the textframe but not gives the choice to remove, skip or find next. I like to use this script as a find and replace palette.

                        • 9. Re: my Find & replace Dialog
                          Haakenlid Level 3

                          You need to be more specific. How is it not working? What exactly do you want help with? How would this find and replace palette be different from the standard palette in InDesign?

                          • 10. Re: my Find & replace Dialog
                            kerosk_inddNew Level 1

                            Dear Haakenlid,

                             

                            I appreciate your time for supporting me. Yesterday, you gave me suggestaion to use #targetengine "session".

                             

                            But I mistakenly run this on InDesing CS3, where I encountered error saying Cannot execute. Sorry for that.

                             

                            Here is my need to develop this script to do:

                             

                            When I run this code it gives me dialog and after click on Remove button it gives an error (see attached pic). I want to modify my code as below:

                             

                            1. Find Next Button : I want to use this button to search my next empty text frame length till end.

                             

                            2. Remove: I want to use this button to remove my empty text frame if I need to delete. After remove my empty textframe my script should be contiue to find  my next empty text frame if any. Just like as a Find & Replace Dialog

                             

                            3. Skip: Please ignore this button. I don't need this.

                             

                            I can't figure out how to accomplish this task through this script.

                             

                            Please help as I can see you have given lots of answers in this fourm.

                             

                            Sincerly thanks for your cooperation.

                            Kerosk

                            Picture 1.png

                             

                             

                            Picture 2.png

                            • 11. Re: my Find & replace Dialog
                              Mac_06 Level 2

                              Change below line

                               

                              var select=app.selection[etf];
                              

                               

                              with this line

                              var select=app.selection[0];
                              

                               

                               

                              Mac

                              • 12. Re: my Find & replace Dialog
                                Haakenlid Level 3

                                Ok. So I think this will do what you want. A couple of things to note:

                                 

                                This will search through every TextFrame in the document. Your script only searched through the first layer. Any reason for that?

                                 

                                 

                                #targetengine "session"
                                 
                                function showDialog(){
                                     app.selection = NothingEnum.NOTHING;
                                     var myTextFrames;
                                     var foundIndex = 0;     
                                     var findNext = function(){
                                          myTextFrames = app.activeDocument.textFrames;
                                          for (etf=foundIndex; etf<myTextFrames.length; etf++){
                                               if (myTextFrames[etf].contents==""){
                                                    app.select(myTextFrames[etf]);
                                                    foundIndex = etf+1;
                                                    app.activeDocument.layoutWindows[0].zoomPercentage=100;
                                                    return;
                                               }
                                          } 
                                          alert ("No more empty Text Frames found");
                                          app.selection = NothingEnum.NOTHING;
                                          foundIndex = 0;
                                          return;
                                     }
                                 
                                     var removeFrame = function(){
                                          if (app.selection.length==0){
                                               alert("Nothing to remove");
                                          } else {
                                               app.selection[0].remove();
                                                  foundIndex--;
                                               findNext();
                                          }
                                     }
                                     
                                     myDialog = new Window("palette", "FindDialog");
                                 
                                     myDialog.myFnBtn = myDialog.add("button", undefined, "Find Next");
                                     myDialog.myFnBtn.onClick = findNext;
                                 
                                     myDialog.myRmBtn = myDialog.add("button", undefined, "Remove");
                                     myDialog.myRmBtn.onClick = removeFrame;
                                 
                                     myDialog.mySkBtn = myDialog.add("button", undefined, "Close");
                                     myDialog.mySkBtn.onClick = function(){
                                          myDialog.close();
                                     }
                                     myDialog.show();
                                     findNext();
                                }
                                          
                                showDialog();
                                
                                • 13. Re: my Find & replace Dialog
                                  kerosk_inddNew Level 1

                                  I want my search on first layer only.

                                   

                                  Anways, your answer is correct, Haakenlid. You have been really very helpful

                                   

                                  You are genius. And you are really a gem for this forum.

                                   

                                  A big thanks for you. God bless you.

                                   

                                  Thanks,

                                  Kerosk

                                  • 14. Re: my Find & replace Dialog
                                    kerosk_inddNew Level 1

                                    Dear Haakenlid,

                                     

                                    Sorry to bother you again. Sometimes I have more than one layers in my doc. So I would like to add one more option in this code, can we add an option for layers search in the palette.

                                     

                                    I mean, there should be one more option for my doc layers in the paletter (see below).

                                     

                                     

                                    Find Next (now this is working)

                                    Remove (now this is working)

                                    Close (now this is working)

                                    Layers(dropdown)         Layer 1 (need this)

                                                                      Layer 2

                                                                      All Layers

                                     

                                    I am sure you will do this.

                                     

                                    Thanks a ton in advance for your cooperation.

                                    Kerosk

                                    • 15. Re: my Find & replace Dialog
                                      Haakenlid Level 3

                                      Implementing a drop down menu is trivial, but I'm not able to make a properly tested code for a few days.

                                       

                                      A simpler solution would be to change this line:

                                       

                                        myTextFrames = app.activeDocument.textFrames;

                                       

                                      To this:

                                       

                                        myTextFrames = app.activeDocument.activeLayer.textFrames; 

                                       

                                      The script will only search through the layer that is currently selected in the Layers palette.

                                       

                                      Note that if you change layers while the palette is open, the next time the "No more empty Text Frames found" alert shows up, it might have missed some text frames on that layer, because foundIndex has not been reset to 0.