1 Reply Latest reply on Jul 9, 2012 12:24 PM by absqua

    How to force script to read a real property?

    Jump_Over Level 5

      Hi,

       

      Help me manage this, pls. We have a textFrame with, say, 3 columns.

      TextColumns line.length is different couse widow/orphans settings.

      shot.jpg

       

      so to fix it I try to run this:

       

      ..................

      // some text in middle column is selected.

      .................

      MC = app.selection[0].textColumns[0];

      Pcount = MC.paragraphs.length;

      lines_count = MC.lines.length;

          if (Pcount > 1) {

              do 

                  for (var x = Pcount-1; x >0; x--) {

                      stopped = x;

                      lines_count1 = MC.lines.length; // shouldn't be changed?

       

                      MC.paragraphs[x].spaceBefore = MC.paragraphs[x].spaceBefore + 1;

                      alert (lines_count1 + "; " + lines_count + "; " + MC.paragraphs[x].spaceBefore);

                      MC.recompose(); // doesn't matter write it or not

                      }

              while (lines_count1 == lines_count); // this stay true

              MC.paragraphs[stopped].spaceBefore = MC.paragraphs[stopped].spaceBefore - 1;

          }

       

      variables "line_count" and "line_count1" should start to differ inside while loop... but they do not. Why?

       

      thx

        • 1. Re: How to force script to read a real property?
          absqua Level 4

          This is the problem with text specifiers that has been discussed a number of times here. Try this modified code:

           

          function main() {
            var column = app.selection[0].textColumns[0],
                paragraphs = column.paragraphs.everyItem().getElements(),
                startLineCount = column.lines.length,
                i;
            
            if (paragraphs.length > 1) {
              do {
                for (i = paragraphs.length - 1; i > 0; i--) {
                  paragraphs[i].spaceBefore += 1;
                }
              } while (startLineCount === column.getElements()[0].lines.length);
          
              for (i = paragraphs.length - 1; i > 0; i--) {
                paragraphs[i].spaceBefore -= 1;
              }
            }
          }
          
          app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT);
          

           

          Jeff

          1 person found this helpful