5 Replies Latest reply on Mar 26, 2016 12:53 PM by Obi-wan Kenobi

    Find frames and resize them! …

    Obi-wan Kenobi Adobe Community Professional

      Hi,

       

      This simple script works fine:

       

      var myTF = app.activeDocument.textFrames.everyItem().getElements()
      for(i=0; i<myTF .length; i++)
      {
          myStoreBounds = myTF[i].geometricBounds 
          myTF[i].geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[0] +50, myStoreBounds[1] +50]
      }
      

       

      But not this one:

       

      var myWidth = "50 mm"
      var myHeight = "50 mm"
      app.activeDocument.textFrames.everyItem().resize(  
            CoordinateSpaces.INNER_COORDINATES,
            AnchorPoint.CENTER_ANCHOR,
            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
            [ myWidth, myHeight ]
      );
      

       

      I'm curious to know why! 

       

      What I truly want to do is: select several graphic frames (not a find/replace and not text frames) and resize them using this: AnchorPoint.CENTER_ANCHOR

      Another way would be to find graphic frames by their color [e.g. "Red"].

       

      Thanks for your help and your lenience! 

        • 1. Re: Find frames and resize them! …
          Peter Kahrel Adobe Community Professional & MVP

          .resize() takes as input only numbers and they are always interpreted as points. To use millimeters, convert them to points:

           

          var myWidth = UnitValue('50mm').as('pt');
          var myHeight = UnitValue('50mm').as('pt');
          

           

          To select several frames and resize them, you could do something like this:

           

          for (i = 0; i < app.selection; i++) {
            app.selection[i].resize(. . .);
          }
          

           

          Peter

          • 2. Re: Find frames and resize them! …
            Obi-wan Kenobi Adobe Community Professional

            Hi Peter,

             

            Thanks for your help!

             

            About the first point, this works fine!    So the 2 versions are OK.

             

            2 last questions about their writing:

            • If I only want to treat graphic or undefined frames, I only found this but I don't really understand if good and how to insert them in the code:


            ObjectTypes.ALL_FRAMES_TYPE    All frame types.

            ObjectTypes.GRAPHIC_FRAMES_TYPE    Graphics frame.

            ObjectTypes.TEXT_FRAMES_TYPE    Text frame.

            ObjectTypes.UNASSIGNED_FRAMES_TYPE    Unassigned frame.

             

            • In this version, where can I add "AnchorPoint.CENTER_ANCHOR" to resize correctly the blocks?

             

            var myTF = app.activeDocument.textFrames.everyItem().getElements()
            for(i=0; i<myTF .length; i++)
            {
                myStoreBounds = myTF[i].geometricBounds
                myTF[i].geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[0] +50, myStoreBounds[1] +50]
            }
            
            

             

             

             

            About the second point, It doesn't work! Surely something I've not understood!

            I've selected some blocks and tried this:

             

            var myWidth = UnitValue('10mm').as('pt'); 
            var myHeight = UnitValue('10mm').as('pt'); 
            for (i = 0; i < app.selection; i++) { 
              app.selection[i].resize( 
                  CoordinateSpaces.INNER_COORDINATES,
                  AnchorPoint.CENTER_ANCHOR,
                  ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                  [ myWidth, myHeight ]);
            }
            
            

             

            Thanks!

            • 3. Re: Find frames and resize them! …
              Peter Kahrel Adobe Community Professional & MVP

              Sorry, in that code, the for loop is wrong, it should be like this:

               

              for (i = 0; i < app.selection.length; i++) {



              • 4. Re: Find frames and resize them! …
                Peter Kahrel Adobe Community Professional & MVP

                If you're after graphic frames, you can do several things.

                1. Graphics are always in a rectangle, never in a text frame, so you could do app.documents[0].rectangles instead of app.documents[0].textFrames.

                2. Get all frames (e.g. select all items on a page), then after line 4 add an if clause: if (app.selection[i] instanceof Rectangle) {

                3. But if you're after all graphics in a document, then it's easiest to go after the document's links: app.documents[0].links. If you have a link object, its parent is the graphic, and its parent in turn is a rectangle. So you'd get something like this:

                 

                var myWidth = UnitValue('10mm').as('pt');
                var myHeight = UnitValue('10mm').as('pt');
                
                var myLinks = app.activeDocument.links.everyItem().getElements();
                
                for (var i = 0; i < myLinks.length; i++) {
                  myLinks[i].parent.parent.resize(
                    CoordinateSpaces.INNER_COORDINATES,
                    AnchorPoint.CENTER_ANCHOR,
                    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                    [ myWidth, myHeight]
                  );
                }
                

                 

                P.

                • 5. Re: Find frames and resize them! …
                  Obi-wan Kenobi Adobe Community Professional

                  Thanks a lot, Peter!