6 Replies Latest reply on Feb 8, 2016 9:32 AM by rob day

    InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error

    Matthias Kolb

      Hey allI want to scroll a textframe by a script in InDesign itself. I'm usinsing ExtendedScript for that and all works fine. First I thought, I could scroll the page like with a mouse, but there ist no scrolling for pages with scripting.

       

       

      What goes wrong:

      When I run the script several times or when the textFrameHight is over 2000, InDesign crashes afzer a few seconds running the script with a memory exception. I think that seems to be a buffer overflow.

       

      How could I get around the memory exception? Or is there another Way to scroll text in InDesign itself?

       

       

      The script:

      var myDocument = app.activeDocument;

      var myPage = myDocument.pages.item(0);

      var myTextFrame = myPage.textFrames.item(0);

      var myX = 0; //statisch; Wieviel vom linken Rand entfernt?

      var myMoveY = 0; //dynamisch; Um wieviel wird nach oben gescrolled?

      var jumpTo = 10; //statisch; Ab wo soll gescrolled werden?

      var myVelocity = -0.1; //statisch; Wie schnell soll gescrolled werden?

      var textframeHight = 7100;

       

       

      if (jumpTo != 0)

      {

          for(var myCounter = 0; myCounter < textframeHight; myCounter ++)

          {

              myMoveY = myCounter * myVelocity + jumpTo;

              myTextFrame.move([myX, myMoveY]);             

           }

      }

      else

      {

          for(var myCounter = 0; myCounter < textframeHight; myCounter ++)

          {

              myMoveY = myCounter * myVelocity;

              myTextFrame.move([myX, myMoveY]);             

           }

      }

       

      Thanks for your help!

       

      Michael

        • 1. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
          Steve Werner Adobe Community Professional & MVP

          If you don't get a reply here, ask in the InDesign Scripting forum:

           

          InDesign Scripting

          • 2. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
            rob day Adobe Community Professional & MVP

            I may not be following what you are trying to do—but your script isn't actually scrolling anything it's moving the first textframe page item on the page 7100 times.

             

            The jumpTo variable is never changed or incremented in the script so the else statement would never be used—the script always moves the text frame page item 7100 times, so it's not surprising you have a memory problem. I assume you expect the 7100 to be pixel units (which in InDesign is always 1/72" no matter what the zoom level)? You're not setting the ruler units to pixels in the script, so if the units are something else the textframe would quickly go off the pasteboard and throw an error. 

             

            Also the myVelocity variable isn't doing much. In the end you are moving the frame's Y one unit at a time— 0, 10.9, 11.9, 12.9 ...

            • 3. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
              rob day Adobe Community Professional & MVP

              I'm more fluent in AppleScript, so here the myVelocity variable would affect the speed of the start to end move. In the AS I'm moving the selected page item

               

              ----------------------

              tell application "Adobe InDesign CC 2014"

                  --set pixel units

                  set properties of view preferences of active document to {horizontal measurement units:pixels, vertical measurement units:pixels, ruler origin:page origin}

                  --the end Y distance

                  set myEnd to 700

                  --the move increment, a higher number moves faster

                  set myVelocity to 3

               

                  repeat with i from 0 to myEnd by myVelocity

                      move selection to {0, i}

                  end repeat

              end tell

               

              --------------------------

               

               

              In JS it should be:

               

              var myPage = myDocument.pages.item(0);

              var myTextFrame = myPage.textFrames.item(0);

              var myX = 0;

              var myVelocity = 3;

              var myEnd = 700;

               

              for(var myCounter = 0; myCounter < myEnd; myCounter +=myVelocity)

              {

                myTextFrame.move([myX, myCounter]);        

              }

              • 4. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
                Matthias Kolb Level 1

                Thank you for your quick reply!

                 

                I have to apologize to not write enough infos regarding the script (cause of mobile lazyness ;-) ).

                 

                Intend:

                Text should scroll (better to say move) vertically to be displayed in a teleprompter (the mirroring and display on a 2nd screen is down with a separate software)

                 

                Situation at the moment:

                Writing the Text in InDesign (cause of usability comfort), export it as jpg and load it in a Browser, where a js scroll this 7100px picture in 2 minutes over the screen.

                 

                Disapointments in this situation:

                . If there is any change in the script, the way from correcting the mistake to display the text again is too complicated and too long - at production time every second counts

                But much more annoying is, that I can't change anything in the script (cause I can't js that well) and when a mistake in the presantation takes place at the end of the text - guess what - we have to reload the jpg in the browser and have to wait nearly 2 minutes to get to the right text passage again...

                 

                The Situation I want to achieve:

                . Setting the text in Indesign - works so well!

                . Calling the Script from ExtendedScript Editor to be executed on the opened Document - this is really manually operated, but it is mandatory for the next and best thing:

                . Changing the vars suitable for the situation I'm in, when producing

                . I have achieved it all already - it works really as expected...the "scrolling" is a little bit unsmooth but it is acceptable...untill it throws the error and crashes

                 

                Here are some vars again with comments:

                var myX = 0; //static; How much away is the text from the left border? Comes in account when the Screen is mirrored on the 2nd display (800 x 600 px) - sometimes I can't see the beginning of the text and changing a var is faster than changes in the mirroring software

                var myMoveY = 0; //dynamic; For calculation the next Y-Coordinate related to the mycounter var

                var jumpTo = 10; //static; From where to scroll? A mistake happend at 6500 px (or units)? Let's start from there.

                var myVelocity = -0.1; //static; How fast should the scrolling be done? Takes place in the calculation of the next Y-Coordinate; Why so small steps? To slowdown the repeating for-loop (Yes this is really novice, but I can't see another affordable way to get an continous move

                var textframeHight = 7100; // static; How long should be scrolled? I know, I could easily read this out from my textframe, but for my first script I want to control that from inside the script, cause for more covenient testing

                 

                To avoid the Memory Overkill, I tried:

                . Looking for a way to move the page, not a textframe into units-nirvana - nothing found

                . Setting the Page dimensions to double of the textframe (InDesign didn't quit that 14200px height - what surprices me) and getting the textframe into the vertical center of the page - of course setting jumpTo to 7100 - Good News: Not throwing the memory exception anymore; the moving works fine until its end and the memory consumption is about 104-110 MB. BUT after it is performed, the memory usage jumps in about 75 MB-steps to 1600 MB and InDesign is frozen away.

                 

                I tried your script. It works fine too, but in the wrong direction and way too fast. The moving should be done in about 120 seconds.

                 

                Unfortunately InDesign isn't supporting the js setInterval. This would be the best solution.

                I found a Script that tries to imitate setIntervat for InDesign, but yesterday I can't get it to work.

                • 5. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
                  Matthias Kolb Level 1

                  Forgot to post the Link to the setTimeOut/setInterval-Script:

                  setTimeOut for InDesign

                  The Author gives the advice to call the setTimeOut again in a own-written Timer-function to imitate setInterval.

                  • 6. Re: InDesign CS5 Scripting Prop: Automatically Scrolling Text results in Memory Error
                    rob day Adobe Community Professional & MVP

                    InDesign isn't a reader application. Who would be using the script? The scripting API for InDesign is intended to speed up page layout production not slow it down, so it's hard to imagine a use for a set interval function.

                     

                    AppleScript has a delay function which you can use to slow things down. So this would reverse the selection's move, and setting the d variable to something greater than 0 would slow down the moves

                     

                    tell application "Adobe InDesign CC 2014"

                        set properties of view preferences of active document to {horizontal measurement units:pixels, vertical measurement units:pixels, ruler origin:page origin}

                        set myEnd to 300

                        set myVelocity to 1

                        set d to 0.1

                        repeat with i from 0 to myEnd by myVelocity

                            delay d

                            move selection to {0, -i}

                        end repeat

                    end tell