4 Replies Latest reply on Sep 20, 2014 6:28 PM by Pandemonico

    Need help to change script findchangebylist.jsx

    Pandemonico

      i did alternate the same vbs script to suit my needs and i was happy about it (likeChild when you give him his favourite toy) but i run in som problems with it....when i copy and place the vbs script on other computer i want it to use it invokes CS6 instead of CC...i tried everything i could think of but no luck...same thing happens every time i try to use it open CS6 instead CC in which i run it...on the computer i did write it the script run like charm(on both computers i have CS6 and CC)....so i decided to use the jsx version of same script....

       

      then when i try that script:

      1. the dialog box is opening only when my cursor is in textframe allowing me to select what i want to change 1.document 2.selected story. 3 selection

      2. when i select 2 text frames and on document i have 3 or more the script does not change in 2 selected frames instead it does in all frames

       

      i need to alternate this script

      when i select text frame to open dialogbox allowing me to pick 2 of 3 above mentioned options the number 2 and 3

      so it do the find and change only in text frames i selected (when it is selected with selection tool) not in all frames

       

      i tried to do that my self but im kinda short of knowledge

       

      i tried to alternate the case dialog box is open adding the line case "TextFrame": in this portion of script

      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":

                          myDisplayDialog();

       

      and it work for invoking the dialog box when the text frame is selected but then it only do changes in first textframe selected not in all selected....

       

      so i tried to experiment with this line

      if(myResult == true){

              switch(myRangeButtons.selectedButton){

                  case 0:

                      myObject = app.documents.item(0);

                      break;

                  case 1:

                      myObject = app.selection[0].parentStory;

                      break;

                  case 2:

                      myObject = app.selection[0];

                      break;

              }

              myDialog.destroy();

              myFindChangeByList(myObject);

          }

          else{

              myDialog.destroy();

          }

      by changing the number to 1 or 2 or 3 but that only told the script that if i have 2 text frame selected to do search in second text frame (incase of number 1) or if i have 3 selected and in case of numer 2 only do script in 3 text frame

       

      i need help please

        • 1. Re: Need help to change script findchangebylist.jsx
          Jump_Over Level 5

          Hi,

           

          In your case app.selection is an array of textFrames and the solution can be to run myFindChangebyList() function to each textFrame - or even better to each parentStory -  (i.e. building a for...loop).

           

          I would move (and duplicate) a line:

               myFindChangebyList(myObject);

          into each "case part" to run it separately.


          After this create a for...loop inside "case 1" to redefine myObject basing on each element of selection and run myFindChangebyList(myObject) step by step with a different target.


          Jarek

          • 2. Re: Re: Need help to change script findchangebylist.jsx
            Pandemonico Level 1

            Thanks for your reply

             

            i tried what you suggested by alternating into this :

                var myResult = myDialog.show();
                if(myResult == true){
                    switch(myRangeButtons.selectedButton){
                        case 0:
                            myObject = app.documents.item(0);
                            myFindChangeByList(myObject);
                            break;
                     case 1:
                            if (app.selection.lenght instanceof Array) 
                            for (var b=0;b<app.selection.lenght; b++) 
                            myObject = app.selection[b].parentStory;
                            myFindChangeByList(myObject);
                            break;
                        case 2:
                            myObject = app.selection[0];
                            myFindChangeByList(myObject);
                            break;
                    }
                    myDialog.destroy();
                }
                else{
                    myDialog.destroy();
                }
            }

            but now i get error for the line 178

             

            var myFoundItems = myObject.changeGrep();

             

            error number: 21 error string: undefined is not an object


            where is the problem??

            • 3. Re: Re: Re: Need help to change script findchangebylist.jsx
              Jump_Over Level 5

              Hi,

               

              I ment something like that:

              //...
              var myResult = myDialog.show();
                if(myResult == true){
                     switch(myRangeButtons.selectedButton){
                          case 0:
                               myObject = app.documents.item(0);
                               myFindChangeByList(myObject);
                               break;
                          case 1:
                               if (app.selection[0].constructor.name == "TextFrame")
                                    for (var b = 0; b < app.selection.length; b++)  {
                                         myObject = app.selection[b].parentStory;
                                         myFindChangeByList(myObject);
                                    }
                               else {
                                    myObject = app.selection[0].parentStory;
                                    myFindChangeByList(myObject);
                                    }
                               break;
                          case 2:
                               myObject = app.selection[0];
                               myFindChangeByList(myObject);
                               break;
                          }
                     myDialog.destroy();
                     }
                     else {
                          myDialog.destroy();
                     }
              //...
              
              

               

              app.selection is an Array but its length is always a Number.

              If 1st element of selection is a TextFrame (maybe more) ==> we go into a loop

              else ==> we call a function as originally.

               

              Jarek

              • 4. Re: Re: Re: Need help to change script findchangebylist.jsx
                Pandemonico Level 1

                thank you o thank you the Great one ...

                 

                it is working...yeaaaaaaaah

                 

                finally when i select 5 frames out of 10 it run only on SELECTED