2 Replies Latest reply on Sep 9, 2009 7:21 PM by John.Kordas

    JS CS3 copy, paste and transform

    John.Kordas Level 1

      I have a script that allows the user to select objects on a page (in this case text frames) and create a new page user defined and then paste the selection on the page and make it fit the page size.

       

      I'm having a slight problem where the text frames in the group are not showing the text (get text overflow) after the resize. If I comment out the myGroup.geometricBounds = [0,0,38,38]; line in the script below and manually resize the group to the document height and width (38,38) the text frames in the group are all ok.

       

       

       

      
      

      var myNewGroup = new Array;

      for (i=app.selection.length-1; i>=0; i--) {

      myNewGroup.push (app.selection[i]);

      }

       

      var myGroup = app.activeDocument.groups.add(myNewGroup);

      myGroup.move(Array(0,0) )

      myGroup.geometricBounds = [0,0,38,38];

       

       

      If anyone has any suggetions it would be greatly appreciated.

       

      John.

        • 1. Re: JS CS3 copy, paste and transform
          John.Kordas Level 1

          I've attached an indesign doc as an example. If I select the group and use the following line:

           

          app.selection[0].geometricBounds = [0,0,38,38];

           

          The group frame is resized but the content is not and all the text frames overflow.  Is there a way to resize the frame and also affect the content, the same way you would manually hold Ctrl and resize the frame?

           

          John.

          • 2. Re: JS CS3 copy, paste and transform
            John.Kordas Level 1

            This seems to be working. I went with the transform() in the end. If anyone has a better way please let  me know.

             

             

             

            
            

            var myNewGroup = new Array;
                 //make group
            for (i=app.selection.length-1; i>=0; i--) {
                myNewGroup.push (app.selection[i]);
                     }
              var myGroup = app.activeDocument.groups.add(myNewGroup);
             
              myGroup.move(Array(0,0) )
                   //get size of group
              var mySelSize = myGroup.geometricBounds;
                     //get size of document
                var myDocHSize = app.activeDocument.documentPreferences.pageHeight;
                var myDocWSize = app.activeDocument.documentPreferences.pageWidth;
                     //get scale value
                var myScalH = myDocHSize/mySelSize[2];
                var myScalW = myDocWSize/mySelSize[3];
                     //apply transform scale
                var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:myScalW, verticalScaleFactor:myScalH});

                myGroup.transform(CoordinateSpaces.pasteboardCoordinates,AnchorPoint.topLeftAnchor, myScaleMatrix);