4 Replies Latest reply on Jul 26, 2017 2:35 AM by DBLjan

    Resize by value with Applescript?

    DBLjan Level 3

      Hello Scripters,

      i need a tiny bit of help to finish the last bit of a quick-and-dirty.

       

      tell application "Adobe InDesign CC 2017"

      set mySel to selection

      set myitem to item 1 of mySel

       

      resize myitem …

       

       

      • I need my selected item (a picture frame) be exactly 9 mm (milimeters) in heigth, width scaling proportional, using the anchor upper left.

       

      Thanks in advance!

        • 1. Re: Resize by value with Applescript?
          Loic.Aigon Adobe Community Professional

          You can use resize or transform with a simple math. However that will not work nicely if item is rotated or skewed or both.

          Dealing with geometry inside indesign is actually a science topic by itself…

           

          tell application "Adobe InDesign CC 2017"
            set sel to selection
            if (count of items in sel) = 0 then
            display dialog "You need one item to be selected"
            
            else
            set doc to active document
            
            set sel to item 1 of sel
            set vb to visible bounds of sel
            set uncertainHeight to ((item 3 of vb) - (item 1 of vb))
            
            set ratio to 9 / uncertainHeight
            
            --Using matrix
            set myTransformationMatrix to make transformation matrix with properties {horizontal scale factor:ratio, vertical scale factor:ratio}
            tell sel to transform in pasteboard coordinates from center anchor with matrix myTransformationMatrix
            
            --OR using resize
            --tell sel to resize in pasteboard coordinates from center anchor by multiplying current dimensions by values {ratio, ratio}
            
            end if
          end tell
          
          • 2. Re: Resize by value with Applescript?
            DBLjan Level 3

            Good job Loic.Aigon !

             

            And I never was close to that code you delivered . Also I didnt know about uncertainHeight, would come in handy in future.

            Have a nice day!

            • 3. Re: Resize by value with Applescript?
              Loic.Aigon Adobe Community Professional

              Once again, uncertainHeight stands for what it means i.e. a possible value for the height. If the item is rotated or skewed or both that will throw a wrong value. Normally it would imply dealing with internal object geometry for stronger results.

              • 4. Re: Resize by value with Applescript?
                DBLjan Level 3

                Thanks for the warning, I'll be careful with my script. But since its for a logo exchange routine, nothing will be skewed or rotated *phew*.