Skip to main content
Known Participant
December 18, 2010
Answered

my Find & replace Dialog

  • December 18, 2010
  • 1 reply
  • 1969 views

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]+".");

                              }
        }

This topic has been closed for replies.
Correct answer

Change below line

var select=app.selection[etf];

with this line

var select=app.selection[0];

Mac


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();

1 reply

Harbs.
Legend
December 18, 2010

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

Known Participant
December 19, 2010

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.

Known Participant
January 13, 2011

Anyone can help me on this.

Really, very eager to find a solution.