5 Replies Latest reply on Jul 16, 2008 12:28 PM by Loic.Aigon

    [CS3 JS] Replacing/Adding text in a table

    Level 1
      Hello professionals....

      I am currently wanting to replace text within a table.
      The Table has 4 simple colums. All text in the table has the same character style.

      b The situation is

      i Here is a short 'cut-out' of the scripting I have done:

      I read in the text bthat needs to be modified from the table with this script:
      > app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
      f = myDoc.findText();
      var myCurrentResponsiblePerson = f[2].contents;
      var myCurrentComments = f[3].contents;

      New text is set to another variable:
      > var myResponsiblePersonField = textEditboxes.add({editContents:myCurrentResponsiblePerson, minWidth:myTextBoxWidth});
      var myCommentField = textEditboxes.add({editContents:myCurrentComments, minWidth:myTextBoxWidth});
      var myCourseRevIndexPerson = myResponsiblePersonField.editContents;
      var myCourseRevIndexComment = myCommentField.editContents;

      I then proceeded to to make a new 'replacement' string:
      > var myCourseRevIndexList = myRevIndex+"\t"+myCourseRevIndexDate+"\t"+myCourseRevIndexPerson+"\t"+myCourseRevIndexCom ment;
      return[myCourseRevIndexList]

      Then I try to 'Change' the text by this:
      > app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
      app.changeTextPreferences.changeTo = oneResult[0];
      oneDoc.changeText();

      Result - InDesign Crashes...!
      What am I doing wrong?
      I know it has something to do with the:
      > app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
      app.changeTextPreferences.changeTo = oneResult[0];

      Because when I deactivate this part - InDesign does
      b not
      crash!

      Would it be better to
      i somehow
      replace the individual text 'cells'?
      If so - how do I do that?
      I have treid to read up, but have had no luck!

      Help / insights would be greatly welcomed.
      Thanks in advance.
      Lee
        • 1. Re: [CS3 JS] Replacing/Adding text in a table
          Loic.Aigon Adobe Community Professional
          Because when I deactivate this part - InDesign does not crash!
          Well, at first glance, you don't define the oneResult array or maybe you did and did not paste here.
          You can use a try/catch method. It may somehow bring you more info on the problem you are facing.
          Could you please paste the whole script so we can test it by our own.

          try //try litteraly written :-)
          {
          //something
          }
          catch(e)
          {
          alert(e);
          }
          • 2. Re: [CS3 JS] Replacing/Adding text in a table
            Level 1
            Thanks for your feedback

            Actually I have made a sort of unprofessional work around:
            > // REVISION INDEX INFORMATION

            // DATE
            app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
            f = myDoc.findText();
            var TXTtochange = f[1].contents;
            var TXTtoReplace = oneResult[10];
            app.findTextPreferences.findWhat = TXTtochange;
            app.changeTextPreferences.changeTo = TXTtoReplace[1];
            oneDoc.changeText();
            app.findTextPreferences = null;
            app.changeTextPreferences = null;
            // PERSON
            app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
            f = myDoc.findText();
            var TXTtochange = f[2].contents;
            var TXTtoReplace = oneResult[10];
            app.findTextPreferences.findWhat = TXTtochange;
            app.changeTextPreferences.changeTo = TXTtoReplace[2];
            oneDoc.changeText();
            app.findTextPreferences = null;
            app.changeTextPreferences = null;
            // COMMENT
            app.findTextPreferences.appliedCharacterStyle = myRevIndexListCharStyleName;
            f = myDoc.findText();
            var TXTtochange = f[3].contents;
            var TXTtoReplace = oneResult[10];
            app.findTextPreferences.findWhat = TXTtochange;
            app.changeTextPreferences.changeTo = TXTtoReplace[3];
            oneDoc.changeText();
            app.findTextPreferences = null;
            app.changeTextPreferences = null;

            This changes the text in seperate cell in the table -
            b but i'm sure it's not the best/correct way!

            My next problem would then be - when I need to
            b add another row
            of information,
            b How would I do that?

            Oh - here's the full script - please change the 'txt' to the usual 'jsx'
            http://www.freetimecorner.ch/joomla2/images/stories/1%29%20create%20new%20document%20-%20v .1.3.txt

            Thanks a MILLION!
            • 3. Re: [CS3 JS] Replacing/Adding text in a table
              Loic.Aigon Adobe Community Professional
              Hi
              I looked at your script and the few answers it gave to me the more answers it brought too :-)
              What is your main idea ? So far what I understood, is that you have this kind of tables and want to easily edit them through a dialog. Is that it ?
              Sorry to ask you these questions that may appear so clear for you but when it could be helpful and useful to really help you.
              Loic
              http://dl.free.fr/cMfRWk3dC/table.pdf
              • 4. Re: [CS3 JS] Replacing/Adding text in a table
                Level 1
                Hello,
                :) Sorry - I should have explained a little more!
                btw - the linked 'pdf' file is blocked for me! Our IT department are very fussy!!! :(

                b What is your main idea?

                We have a 3 sided document (Title page, Content page, Release page) to present our product - Training Courses.

                On each side of the document there are certain informations that are the same. To make life easy for the people editing these documents, it was decided to make a script to automate the input and changing of these informations.

                Character Sytles were generated to define each field of information, so to aid in the find/Change of the scripting.

                On the Title page there is the 'Course Title', 'Course Reference No.' and 'Document No.' information.

                On the Content page there is the 'Course Title', 'Course Sub-Title', 'Reference No.' and 'Document No.' informations (naturally there is all the course info too, but that's a 'one-time-entry' only).

                On the Release page there is all the above and a
                b table
                that contains the latest revision index information. i.e. Revsion Index, Date of Changes, Responsible Person, Comments to changes made.
                This row of information has a Character Style and is read in.
                I then searched the string and replaced each Array position with the previously entered text.

                It seems to work OK for when you are creating the
                b first document
                !

                My problem what I see coming is the fact that when it is needed to enter a revision - how would I
                b add
                another row
                b and
                then select only the last row of - then to be 'blank' information?

                Did this help?

                If it might help - here is the InDesign 'template' file that they start with:
                http://www.freetimecorner.ch/joomla2/images/allsorts/course_description_end.txt

                b NOTE

                Change the 'txt' for 'indt'
                In the script you'll have to change the address when he goes to open this file (
                i in the top few lines
                )
                • 5. Re: [CS3 JS] Replacing/Adding text in a table
                  Loic.Aigon Adobe Community Professional
                  hi Lee,
                  Now I got the full idea. thanks for sending the files.
                  My thought is : Aren't you making the things harder than they need ? Or maybe you are too consciencious :-)
                  Looking to the final table and your fear about adding a row, I would say what about getting rid of the table ?
                  I mean, why not simulate a table that would be a compilation of textFrames. Adding one, would be a short and easy work for recompositing the whole "table".
                  The interest is that labelling the textFrames, you can adress the changes maybe more directly than finding and search the texts throough the character styles.
                  So you have a labeled course title textframe that you can easily change with the input.
                  var coursetitleTf = app.documents.item("doc.indd").pages[2].textFrames.item("coursetitleTf");
                  // X is the data from the dialog
                  coursetitleTf.contents = X;
                  (It 's a short explanation but I am sure you will have understood what I am talking about).
                  So at the end, if you havr to recompose your "table" adding a pseudo row, it won't affect the way you speak to other rows cause labels will be preserved.
                  That's my idea and probably how I will do.
                  Hope it helps, keep me in touch when you got your solution.
                  Loic