5 Replies Latest reply on Mar 4, 2009 11:31 AM by Jeremy bowmangraphics-DQuh1B

    script request

    Lorna Hadley
      I am looking, in vain it seems, for a script that will add .125 inches or 0p9 horizontally and vertically from the center of a box. eg., if my box was 2 x 2 inches, I would like the box to end up being 2.125 x 2.125 added from the center of the box. Is this possible and would anyone be interested in making a script that would do this?
      Thanks!
      Lorna
        • 1. Re: script request
          Kasyan Servetsky Level 5
          Hi Lorna,

          I assume that one box is selected in the current document. But there is not enough information in your post: which box should be transformed – graphic/text frame, only selected frame or all on the page /spread/ in document etc.

          Kasyan

          if (app.selection.length > 0) {
          
             var mySelection = app.selection[0];
          }
          else {
             alert("Select a box.");
             exit();
          }
          var myBounds= mySelection.geometricBounds;
          var myWidth = myBounds[3] - myBounds[1];
          var myHeght = myBounds[2] - myBounds[0];
          var myHorScaleFactor = (myWidth + 0.125)/myWidth;
          var myVerScaleFactor = (myHeght + 0.125)/myHeght;
          var myTransformationMatrix = app.transformationMatrices.add({horizontalScaleFactor:myHorScaleFactor, verticalScaleFactor:myVerScaleFactor});
          mySelection.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.CENTER_ANCHOR, myTransformationMatrix);
          • 2. Re: script request
            Jeremy bowmangraphics-DQuh1B Level 3
            Warning: I'm an amateur! But this seems to work for me. Select the box you want to expand, then run the script.

            if (app.documents.length > 0){
            
               var myDocument = app.activeDocument;
               var myViewPreferences = myDocument.viewPreferences;
               var myOldXUnits =
            myViewPreferences.horizontalMeasurementUnits;
               var myOldYUnits = myViewPreferences.verticalMeasurementUnits;
               var myOldRulerOrigin = myViewPreferences.rulerOrigin;
               myDocument.viewPreferences.horizontalMeasurementUnits
            = MeasurementUnits.points;
               myDocument.viewPreferences.verticalMeasurementUnits
            = MeasurementUnits.points;

               if (app.selection.length == 1){
                  var myBox = app.selection[0];
                  if (myBox.constructor.name ==
            "TextFrame" || myBox.constructor.name == "Rectangle"){
                     myExpand(myBox);
                     }
                  else
                     alert("You
            haven't selected a box as required. Select a box and try again.");
                     } 
                  app.activeDocument.viewPreferences.horizontalMeasurementUnits
            = myOldXUnits;
                  app.activeDocument.viewPreferences.verticalMeasurementUnits
            = myOldYUnits;
                  app.activeDocument.viewPreferences.rulerOrigin
            = myOldRulerOrigin;
               }

            function myExpand(myBox) {
               var myBounds = myBox.geometricBounds;
               myBox.geometricBounds = [myBounds[0] - 4.5,
            myBounds[1] - 4.5, myBounds[2] + 4.5, myBounds[3]+4.5];
               } //end function myExpand
            • 3. Re: script request
              Jeremy bowmangraphics-DQuh1B Level 3
              Ooops! -- Didn't see that your question had already been answered!
              • 4. Re: script request
                Lorna Hadley Level 1
                OH so sorry! I didn't realize you would need this info (duh!). I would like to expand selected graphic boxes only. We place files in indesign to manually step files for gang runs on our DI and I end up expanding these boxes manually, that's a lot of '+.125' input!
                Thanks for your quick responses, you guys are terrific!
                • 5. Re: script request
                  Jeremy bowmangraphics-DQuh1B Level 3
                  This version expects you to manually select a bunch of graphic boxes and then run the script:

                  if (app.documents.length > 0){
                  
                    var myDocument = app.activeDocument;
                    var myViewPreferences = myDocument.viewPreferences;
                    var myOldXUnits = myViewPreferences.horizontalMeasurementUnits;
                    var myOldYUnits = myViewPreferences.verticalMeasurementUnits;
                    var myOldRulerOrigin = myViewPreferences.rulerOrigin;
                    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

                     if (app.selection.length != 0){
                        myList = app.selection;
                        for (var i = 0; i < myList.length; i++){
                           var myBox = app.selection[i];
                           if (myBox.constructor.name == "TextFrame" || myBox.constructor.name == "Rectangle"){
                           myExpand(myBox);
                           }
                        else
                           alert("The script stopped running because a non-recrangle was selected.");
                          }
                      }
                     app.activeDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;
                     app.activeDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;
                     app.activeDocument.viewPreferences.rulerOrigin = myOldRulerOrigin;
                     }

                  function myExpand(myBox) {
                    var myBounds = myBox.geometricBounds;
                    myBox.geometricBounds = [myBounds[0] - 4.5, myBounds[1] - 4.5, myBounds[2] + 4.5, myBounds[3] + 4.5];
                    } //end function myExpand