6 Replies Latest reply on Feb 10, 2015 5:24 PM by elaineg94828332

    Multiple graphic frames: resize, fit content proportionally, center content

    elaineg94828332

      Hello scripting wizards! I'm hoping one of you can help me with this simple task. How I wish actions were an option! I've read the posts saying how simple apple scripting is. I've read the tutorial from start to finish and done the exercises. I've copied snippets from multiple sources and the only thing I've been able to do is fit content ... but not proportionally.

       

      I'm using INDD CC. I have a dozen tabloid size pages with a hundred placed illustrator images on each. Here's what I need to do to every one of graphic frames:

      1. make all the graphic frames the same size: 10mm x 10mm

      2. fit content to frame proportionally

      3. center content in frame

       

      Can anyone help? Thanks!

        • 1. Re: Multiple graphic frames: resize, fit content proportionally, center content
          Kevin Parrott Level 2

          Hi

           

          this should get you moving in the right direction

           

          tell application "Adobe InDesign CC 2014"

              activate

              set myDoc to active document

              tell myDoc

                  set transform reference point of layout window 1 to center anchor

                  set geometric bounds of rectangles of active layer to {0, 0, 10, 10}

                  fit rectangles of active layer given center content

                  fit rectangles of active layer given proportionally

              end tell

          end tell

          • 2. Re: Multiple graphic frames: resize, fit content proportionally, center content
            elaineg94828332 Level 1

            Thank you; it's SO close! Everything works great, except the frames all align at the top left of the window (0,0) instead of staying where they are on the page.

             

            I unsuccessfully tried replacing set transform ... and set geometric ... with the following:

            resize rectangles in geometric path bounds from center anchor by replacing current dimensions with values {10, 10 [, mm]} but that didn't do it.

             

            I also found a seemingly relevant snippet but I'm not sure how to use it:

            set {a, b, c, d} to geometric bounds

            set geometric bounds to {a, b, (c + 10), (d + 10)}

            • 3. Re: Multiple graphic frames: resize, fit content proportionally, center content
              elaineg94828332 Level 1

              Hi Kevin,

               

              After dogging this all day yesterday (and the day before) I was a bit delirious last night when I said that "everything works except ..." It successfully resizes the frame and fits content to frame, but does not center the content in the frame or leave the frame where it is. Any ideas?

              • 4. Re: Multiple graphic frames: resize, fit content proportionally, center content
                Kevin Parrott Level 2

                hi Elaine

                 

                being playing around with this script, It might just be my settings here, but I cant get it to work in mm

                so I have changed it to work in points, so 28.3464567 = 10mm, see how this works for you.

                 

                 

                tell application "Adobe InDesign CC 2014"

                    activate

                    set myDoc to active document

                    tell myDoc

                        tell view preferences

                            set ruler origin to page origin

                            set horizontal measurement units to points --millimeters (couldnt get it to work using mm)

                            set vertical measurement units to points --millimeters

                        end tell

                        set transform reference point of layout window 1 to center anchor

                        set theRects to rectangles of myDoc

                        repeat with i from 1 to count of theRects

                            set MyNewSize to item i of theRects

                            resize MyNewSize in geometric path bounds from center anchor by replacing current dimensions with values {28.3464567, 28.3464567}

                        end repeat

                        fit rectangles of active layer given center content

                        fit rectangles of active layer given proportionally

                    end tell

                end tell

                • 5. Re: Multiple graphic frames: resize, fit content proportionally, center content
                  Kevin Parrott Level 2

                  forgot to replace the view preferences with the original view prefs.

                   

                  tell application "Adobe InDesign CC 2014"

                      activate

                      set myDoc to active document

                      tell myDoc

                          set OrigViewPrefs to properties of view preferences

                         

                          tell view preferences

                              set ruler origin to page origin

                              set horizontal measurement units to points --millimeters (couldnt get it to work using mm)

                              set vertical measurement units to points --millimeters

                          end tell

                         

                          set transform reference point of layout window 1 to center anchor

                          set theRects to rectangles of myDoc

                          repeat with i from 1 to count of theRects

                              set MyNewSize to item i of theRects

                              resize MyNewSize in geometric path bounds from center anchor by replacing current dimensions with values {28.3464567, 28.3464567}

                          end repeat

                          fit rectangles of active layer given center content

                          fit rectangles of active layer given proportionally

                         

                          tell view preferences

                              set horizontal measurement units to horizontal measurement units of OrigViewPrefs

                              set vertical measurement units to vertical measurement units of OrigViewPrefs

                          end tell

                         

                      end tell

                  end tell

                  • 6. Re: Multiple graphic frames: resize, fit content proportionally, center content
                    elaineg94828332 Level 1

                    Hi Kevin,

                     

                    Those dang millimeters! The script I came up with defaulted to pixels of all things. So my solution (actually two scripts) isn't pretty but it works though it paints with a wide brush ... every rectangle. I hope to add a repeat line like yours so I can select only the ones I want. A blogger out there in Scripter Land sent me some ideas of how to combine and improve them; I hope to dig into their logic soon. These are the two I came up with:


                    Resize frame 10mm x 10mm

                     

                    tell application "Adobe InDesign CC 2014"

                      activate

                      tell active document

                      resize every rectangle in inner coordinates from center anchor by replacing current dimensions with values {30, 30}

                      end tell

                    end tell

                     

                    Fit content to frame (proportionally and centered)

                     

                    tell application "Adobe InDesign CC 2014"

                      activate

                      tell the active document

                      tell every rectangle

                      fit given content to frame

                      fit given proportionally

                      fit given center content

                      end tell

                      end tell

                    end tell