9 Replies Latest reply on Feb 2, 2011 2:36 AM by [Jongware]-9BC6tI

    Resize frame 1/8" all sides script

    macinbytes Level 4

      I'm looking for something relatively simple in terms of a script for one of our prepress guys. I don't think they really need any sort of an addon or plug for it and I believe a Javascript or Applescript would work better than the manual steps they go about to accomplish it.


      What I need is a script that will take a group of objects and add 1/8" to all sides of each frame to account for our standard bleed setting. In all cases they are working with either unassigned or unfilled frames, never text involved. Ideally I would have them something that adds 1/8" and something that subtracts 1/8". Always 1/8", always all 4 sides.


      Anyone have a precanned set of scripts that I can modify for this purpose or some savvy to off the cuff something close?


      Thanks in advance,


        • 1. Re: Resize frame 1/8" all sides script
          [Jongware] Most Valuable Participant

          Beware! Making this up without using either a help guide or InDesign itself! Use at your own (etc.etc.)


          Assuming you have selected the frames to adjust, you can iterate through the selection and modify the geometricBounds of each frame:


          for (a=0; a<app.selection.length; a++)
            oldbounds = app.selection[a].geometricBounds;
            newbounds = [oldbounds[0] - 0.125, oldbounds[1] - 0.125, oldbounds[2] + 0.125, oldbounds[3] + 0.125 ];
            app.selection[a].geometricBounds = newbounds;


          The geometricBounds property of a frame is a four element array, holding (in this order) top y, left x, bottom y, right x coordinates, relative to the current zero point (which is irrelevant here, as we are only adding/subtracting), and in your current measurement units (which is highly relevant, as we are adding/subtracting 1/8 in whatever the current measurement units are).


          This piece of code expands your frames; if you draw a rectangle on a piece of paper and label top y, left x, bottom y, and right x, you can see when to add or subtract. Reverse this to contract them again.

          • 2. Re: Resize frame 1/8" all sides script
            macinbytes Level 4

            Perfect! Works like a charm.

            • 3. Re: Resize frame 1/8" all sides script



              Say I wanted to do this to all of the rectangle frames on a specific layer in a document, is that possible. How would that look in terms of the Javascript code?



              • 4. Re: Resize frame 1/8" all sides script
                [Jongware]-9BC6tI Level 4

                Well, since Layers have a property "rectangles", it's fairly easy to loop over all of a certain layer's items and do this calculation on each one of 'em.

                It'd look like (pseudocode)


                let someLayer be some Layer

                  for each rectangle on that layer

                    do the transformation on it

                • 5. Re: Resize frame 1/8" all sides script
                  hmtyrant Level 1

                  Thanks for the swift reply, Im sorry, but I do not see any code. Is there anyway for you to show me the javascript code for this?



                  • 6. Re: Resize frame 1/8" all sides script
                    [Jongware]-9BC6tI Level 4

                    Yes, that's why I said it's pseudocode -- outlining just the steps, without going into any platform- or language-specific detail. That's why it's called 'pseudo'.


                    It's as I said, as easy as


                    myLayer = app.activeDocument.layers[0];
                    for (r=0; r<myLayer.rectangles.length; r++)
                    oldbounds = myLayer.rectangles[r].geometricBounds;
                    newbounds = [oldbounds[0] - 0.125, oldbounds[1] - 0.125, oldbounds[2] + 0.125, oldbounds[3] + 0.125 ];
                    myLayer.rectangles[r].geometricBounds = newbounds;


                    (Still untested, tho'. At least it is Javascript.)

                    • 7. Re: Resize frame 1/8" all sides script
                      hmtyrant Level 1

                      Thank you so much!

                      Just for future reference, is there somewhere I can go to interpret pseudocode into javascript. Do you know what I mean? Seems like a great way to learn javascript.

                      • 8. Re: Resize frame 1/8" all sides script
                        [Jongware]-9BC6tI Level 4

                        Pseudocode is a way of outlining the steps for yourself, without going into specific detail. It's like drawing a flow-chart on a notepad.

                        The idea is to get a handle on the different stages a program should go through, and in which order. You can add as little or as much detail as you want, until you are ready to translate it (yourself) into actual code.


                        For instance, suppose you want to write a sliding puzzle:




                        You need this rough outline:


                        set up puzzle

                        while (not in correct order)

                            wait for user to make a move

                        show time


                        What code is needed to set up the puzzle? It doesn't matter -- it can be done in twenty different ways, but the end result of "set up puzzle" should be a randomly slided, but still valid puzzle. How would you draw it on the screen? Can be decided later. How does the user make a move? Let's think about that, because that's not straightforward:


                        onClick (at a square)

                           if (square is empty)

                              do nothing

                           if (square to left is empty)

                              move this to the left

                           (same for the other 3 directions)


                        By adding more and more detail, you get closer and closer from a pure textual description to actual commands to be programmed.


                        When writing a new program, I often type in pseudocode while thinking about how to do stuff, and then replace it line by line with actual code.

                        • 9. Re: Resize frame 1/8" all sides script
                          [Jongware]-9BC6tI Level 4

                          By the way: See http://en.wikipedia.org/wiki/Pseudocode for a pretty good introduction to the concept.


                          ... Although the links at the bottom go into way too much detail! There is no need at all for a "Pseudocode Standard" (which would effectively become a 'programming language' on its own, and thus eliminate the need for pseudocode; except when you write pseudocode for programming in that ... and so on). But it makes a good point, which I didn't think of: you don't have to change your lines of pseudocode into actual code. Leave the original text in your program, but make them a comment; that way, you can follow your original train of thought when you look later at your code.


                          The Pseudocode Guidelines PDF tells a bit more about the notational style. I guess the main point is, you should use a shorthand notation where for each single line you know you can write the code for. And that changes over time. As per my previous example: if you want to set up the sliding puzzle board, you might (initially) need to explicitly remind yourself to:


                          set up puzzle:

                            create an array of 4 x 4 positions

                            fill first 15 with numbers 1 to 15, last one with 0 ("empty")

                            do for a random amount of time

                               swap 0 with one on its left, right, top, or bottom


                          .. where all I need is the single line "set up the darn stuff". As your experience increases, you'll find less need for explicitly writing out each single step, and find yourself focusing more on "the big plan". Perhaps one day I'll be able to finally expand this pseudocode into a fully working program:


                          write fantastic program

                          put on internet

                          while cash is flowing in