10 Replies Latest reply on Oct 15, 2008 12:59 PM by (Dave_Saunders)

    Need a command string for...

    Randall86
      I am trying to script Indesign CS3 with JavaScript on my Mac Pro, so I can auto page books, I have to have keeping option turned on so at the bottom of a page I can have up to 4 lines worth of space. If it has over a certain amount of space I have to go in and manually adjust word spacing to try and get it pulled up. Any ideas on how to tell my script to pause in cycling through the book if there is that much space at the bottom? I don't even know how Indesign looks at that space...
      I am running leopard.
        • 1. Re: Need a command string for...
          [Jongware] Most Valuable Participant
          You can't easily tell ID to pause a script. However, I think it is possible to check for more than 4 blank lines at the bottom of a textframe.

          (Just thinking out loud.)

          TextFrame has a
          b lines
          property. Therefore, "myTextFrame.lines.length" holds the number of lines. If your leading is the same all over the page and you don't have any space above or below paragraphs, you're done: your typical page can hold (say) 40 lines, myTextFrame.lines.length is 30, so there are 10 blank lines. Unlikely, but a good start, innit? ;-)

          If you know the number of lines in a text frame, you can access the properties of the
          b last
          line, for example, "endBaseline" ("Vertical offset of the end of the text"). Now you have a vertical position with "myTextFrame.lines[myTextFrame.lines.length-1].endBaseline". Compare this with the bottommost possible position, and you know how much
          i space
          you have at the bottom. Then your script can decide if and how to pull up some text from the next page.

          Which (while typing) made me think: how are you going to get more lines using word spacing? You must mean
          i line
          spacing instead, and that means your script (or, in the case of manually tinkering, you) has to go over the lines in that particular text frame and adjust line spacing and/or paragraph spacing until you get the required space for a few lines more.

          What if the paragraph on the next page cannot be run in, because it's a heading (with accompanying white space above and below, and has to tag along a few lines of text as well) or because it's a three-line paragraph (which, under regular circumstances, may not be broken into 2-then-1 line or 1-then-2 lines)?
          • 2. Re: Need a command string for...
            Randall86 Level 1
            Actually since all our books are full justified I can use word spacing to force a paragraph longer or shorter to make it wrap or pull up. We also only have one possible font size or leading and three different paragraph styles but I have already figured out how to make avoid trouble with the paragraph styles. honestly the standards we have doesn't leave much room for creativity but does open the door to automation. Thanks for the hint I'll give it a shot and see if it works.
            • 3. Re: Need a command string for...
              [Jongware] Most Valuable Participant
              >since all our books are full justified I can use word spacing to force a paragraph longer or shorter to make it wrap or pull up

              Yeah, I have a script that does just that -- decrease tracking until the paragraph is just a single line shorter. I have to manually select candidates, though. I can try to write a version that works on an entire page and selects the best possible candidate by itself :-) (And if that works, let it loose on an entire document.)

              Regarding my last question/pondering: perhaps the script could run in one line, then check if it made things better, i.e., if the frame indeed now contains more lines than before. If not, it could revert its doings and continue with the next page.
              • 4. Re: Need a command string for...
                Level 1
                CS4 isn't out yet, but it is relevant to mention that its paragraph composer is far less likely to create short last lines in left justified paragraphs than are any of its predecessors.

                Dave
                • 5. Re: Need a command string for...
                  Randall86 Level 1
                  Really? Thats great, I have noticed CS4 seems to be promising a great deal. does anyone know if CS3 scripts will be directly compatible with CS4? Jongware I would love to take a look at that tracking script your talking about I bet that could be a life saver.
                  • 6. Re: Need a command string for...
                    [Jongware] Most Valuable Participant
                    Here it is:

                    if (app.selection[0].constructor.name == "InsertionPoint")
                    

                    {

                    var l = app.selection[0].paragraphs[0].lines.length;

                    if (l < 2)

                    {

                      alert ("Just 1 line -- can't run in :-(");

                      exit(0);

                    }

                    // alert ("Num lines is "+l);

                    var org_track = app.selection[0].tracking;

                    var track = app.selection[0].tracking;

                    // alert ("Tracking is "+track);

                    while (app.selection[0].paragraphs[0].lines.length == l)

                    {

                      track--;

                      app.selection[0].paragraphs[0].tracking = track;

                      if (app.selection[0].paragraphs[0].lines.length == l)

                       app.selection[0].paragraphs[0].tracking = org_track;

                    }

                    if (org_track - track > 10)

                    {

                      if (confirm ("Tracking was "+org_track+", is nu "+track+"!\nUndo?") == true)

                       app.selection[0].paragraphs[0].tracking = org_track;

                    }

                    }

                    Put the text cursor into a paragraph with (preferably) lots of lines and a short last one.
                    It tracks up to -10 of the original value (whatever that was) without warning. If more, you get a warning, and since you most likely don't want a tracking of more, the default is "Yes" -- simply hit Enter to undo.
                    It does some trickery with resetting-then-setting the new value, so if you don't like it, you only need a single Undo.
                    • 7. Re: Need a command string for...
                      Level 1
                      There are some changes, but not many (although, obviously, there's a lot of new stuff to support the new featres). As soon as CS4 hits the street, I'll start a "What's changed" topic.

                      Dave
                      • 8. Re: Need a command string for...
                        Randall86 Level 1
                        Thanks for your help Guys I got it working!
                        • 9. Re: Need a command string for...
                          GagnonEric Level 1
                          "CS4 isn't out yet, but it is relevant to mention that its paragraph composer is far less likely to create short last lines in left justified paragraphs than are any of its predecessors."

                          I'm interessed to hear more about that one!

                          I had to deal with alot of "orphans" in a recent project. Manually correcting them was not a very practical solution because of the automation (had to redo the correction every time the document is regenerated from database). I have tried using "balance ragged lines" by exemple, but it was affecting pretty much all the text, not just the ones with one word alone on the last line...
                          • 10. Re: Need a command string for...
                            Level 1
                            CS4 is out now. Early in the beta cycle, I reported the CS3 propensity for having short lines at the end of justified paragraphs (not full justified of course) and the engineering team took a good look at it and realized that while the behavior didn't quite warrant being called a bug, it was the result of a weakness in the algorithm, where they were in effect applying full justify and then setting the last line to be left (or whatever) aligned.

                            This often results in the text on that line taking more space and that's where the short lines come from. The CS4 algorithm avoids this, keeping the last line justified as long as it fits within your settings.

                            Dave