1 Reply Latest reply on Apr 6, 2017 9:59 AM by davidsonjw

    How to specify the myBounds as the page bounds

    davidsonjw

      I am working on a script that will eventually be applied to a master page and this is only part of the script. I would like to add crop marks to a page. The page size will not be fixed, so I would like the bounds to be based on the page bounds rather than a SET bounds.

       

      Below is what I have so far. Any help on this would be greatly appreciated.

       

          //Crop Marks

          var myCropMarkLength = 15.12;

          var myCropMarkOffset = 20.88;

          var myCropMarkWidth = .25;

       

       

          var myDocument = app.activeDocument;

          var myOldRulerOrigin = myDocument.viewPreferences.rulerOrigin;

          myDocument.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;

          //Save the current measurement units.

          var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;

          var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;

          //Set the measurement units to points.

          myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

          myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

          {//Create a layer to hold the printers marks (if it does not already exist).

          var myLayer = myDocument.layers.item("myCropMarks");

          try{

              myLayerName = myLayer.name;

          }

          catch (myError){

              var myLayer = myDocument.layers.add({name:"myCropMarks"});

          }

          }

          //Get references to the Registration color and the None swatch.

          var myRegistrationColor = myDocument.colors.item("Registration");

          var myNoneSwatch = myDocument.swatches.item("None");

         

          var myBounds = myDocument.Bounds;

          var myY1 = myBounds[0];

          var myX1 = myBounds[1];

          var myY2 = myBounds[2];

          var myX2 = myBounds[3];

       

       

          function myDrawCropMarks (myX1, myY1, myX2, myY2, myCropMarkLength, myCropMarkOffset, myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer){

       

          //Upper left crop mark pair.

          myDrawLine([myY1, myX1-myCropMarkOffset, myY1, myX1-(myCropMarkOffset + myCropMarkLength)], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

          myDrawLine([myY1-myCropMarkOffset, myX1, myY1-(myCropMarkOffset+myCropMarkLength), myX1], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

       

          //Lower left crop mark pair.

          myDrawLine([myY2, myX1-myCropMarkOffset, myY2, myX1-(myCropMarkOffset+myCropMarkLength)], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

          myDrawLine([myY2+myCropMarkOffset, myX1, myY2+myCropMarkOffset+myCropMarkLength, myX1], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

       

          //Upper right crop mark pair.

          myDrawLine([myY1, myX2+myCropMarkOffset, myY1, myX2+myCropMarkOffset+myCropMarkLength], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

          myDrawLine([myY1-myCropMarkOffset, myX2, myY1-(myCropMarkOffset+myCropMarkLength), myX2], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

       

          //Lower left crop mark pair.

          myDrawLine([myY2, myX2+myCropMarkOffset, myY2, myX2+myCropMarkOffset+myCropMarkLength], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

          myDrawLine([myY2+myCropMarkOffset, myX2, myY2+myCropMarkOffset+myCropMarkLength, myX2], myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);

          }

          function myDrawLine(myBounds, myStrokeWeight, myRegistrationColor, myNoneSwatch, myLayer){

          app.activeWindow.activeSpread.graphicLines.add(myLayer, undefined, undefined,{strokeWeight:myStrokeWeight, fillColor:myNoneSwatch, strokeColor:myRegistrationColor, geometricBounds:myBounds})

          }

        • 1. Re: How to specify the myBounds as the page bounds
          davidsonjw Level 1

          myDocument = app.activeDocument;

           

          //Change Unit of Meausre to Points

          myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

          myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

          var myCropMarkLength = 15.12;

          var myCropMarkOffset = 20.88;

          var myCropMarkWidth = .25;

          var myPH = myDocument.documentPreferences.pageHeight;

          var myPW = myDocument.documentPreferences.pageWidth;

           

          //Upper Left Crop Mark Pair

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH - myPH, (myPW - myPW) - myCropMarkOffset, myPH - myPH, (myPW - myPW) - (myCropMarkOffset + myCropMarkLength) ];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [(myPH - myPH) - myCropMarkOffset, myPW - myPW, (myPH - myPH)  - (myCropMarkOffset + myCropMarkLength), myPW - myPW];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          //Lower Left Crop Mark Pair

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH, (myPW - myPW) - myCropMarkOffset, myPH, (myPW - myPW) - (myCropMarkOffset + myCropMarkLength) ];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH + myCropMarkOffset, myPW - myPW, myPH + (myCropMarkOffset + myCropMarkLength), myPW - myPW];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          //Upper Right Crop Mark Pair

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH - myPH, myPW + myCropMarkOffset, myPH - myPH, myPW + (myCropMarkOffset + myCropMarkLength) ];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [(myPH - myPH ) - myCropMarkOffset, myPW, (myPH - myPH) - (myCropMarkOffset + myCropMarkLength), myPW];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          //Lower Right Crop Mark Pair

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH, myPW + myCropMarkOffset, myPH, myPW + (myCropMarkOffset + myCropMarkLength) ];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();

          myOutsideGuide_Left.geometricBounds = [myPH + myCropMarkOffset, myPW, myPH + (myCropMarkOffset + myCropMarkLength), myPW];

          myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

           

          //Change Unit of Measure Back to Inches

          myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;

          myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;