5 Replies Latest reply on May 15, 2017 5:52 AM by tpk1982

    Crop mark

    tpk1982 Level 4

      Hi,

       

      I am trying to modify the cropmark script as per my requirement. But little confused how to eliminate the cropmarks which comes in middle. Please suggest how to get rid this.

       

      Screen Shot 2017-05-15 at 1.02.16 PM.png

       

      Script:

       

      main();
      function main(){
        //Make certain that user interaction (display of dialogs, etc.) is turned on.
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
        if (app.documents.length != 0){
        if (app.selection.length > 0){
        switch(app.selection[0].constructor.name){
        case "Rectangle":
        case "Oval":
        case "Polygon":
        case "GraphicLine":
        case "Group":
        case "TextFrame":
        case "Button":
        myDisplayDialog();
        break;
        default:
        alert("Please select a page item and try again.");
        break;
        }
        }
        else{
        alert("Please select an object and try again.");
        }
        }
        else{
        alert("Please open a document, select an object, and try again.");
        }
      }
      function myDisplayDialog(){
        var myDialog = app.dialogs.add({name:"CropMarks"});
        with(myDialog){
        with(dialogColumns.add()){
        var myCropMarksGroup = enablingGroups.add({staticLabel:"Crop Marks", checkedState:true});
        with (myCropMarksGroup){
        with(borderPanels.add()){
        staticTexts.add({staticLabel:"Options:"});
        with (dialogColumns.add()){
        staticTexts.add({staticLabel:"Length:"});
        staticTexts.add({staticLabel:"Offset:"});
        staticTexts.add({staticLabel:"Stroke Weight:"});
        }
        with (dialogColumns.add()){
        var myCropMarkLengthField = measurementEditboxes.add({editValue:18, editUnits:MeasurementUnits.points});
        var myCropMarkOffsetField = measurementEditboxes.add({editValue:3, editUnits:MeasurementUnits.points});
        var myCropMarkWidthField = measurementEditboxes.add({editValue:.5, editUnits:MeasurementUnits.points});
        }
        }
        }
      
      
        with(borderPanels.add()){
        staticTexts.add({staticLabel:"Draw Marks Around:"});
        var myRangeButtons = radiobuttonGroups.add();
        with(myRangeButtons){
        radiobuttonControls.add({staticLabel:"Each Object", checkedState:true});
        radiobuttonControls.add({staticLabel:"Entire Selection"});
        }
        }
        }
        }
        var myReturn = myDialog.show();
        if (myReturn == true){
        //Get the values from the dialog box.
        var myDoCropMarks = myCropMarksGroup.checkedState;
        var myCropMarkLength = myCropMarkLengthField.editValue;
        var myCropMarkOffset = myCropMarkOffsetField.editValue;
        var myCropMarkWidth = myCropMarkWidthField.editValue;
        var myRange = myRangeButtons.selectedButton;
        myDialog.destroy();
        //"||" is logical OR in JavaScript.
        if ((myDoCropMarks != false) ){
        myDrawPrintersMarks(myRange, myDoCropMarks, myCropMarkLength, myCropMarkOffset, myCropMarkWidth);
        }
        else{
        alert("No printers marks were selected.");
        }
        }
        else{
        myDialog.destroy();
        }
      }
      function myDrawPrintersMarks(myRange, myDoCropMarks, myCropMarkLength, myCropMarkOffset, myCropMarkWidth){
        var myBounds, myX1, myY1, myX2, myY2, myObject;
        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");
        //Process the objects in the selection.
        myBounds = myDocument.selection[0].visibleBounds;
        for(var myCounter = 0; myCounter < myDocument.selection.length; myCounter ++){
        myObject = myDocument.selection[myCounter];
        myBounds = myObject.visibleBounds;
        //Set up some initial bounding box values.
        if ((myRange != 0)&&(myCounter==0)){
        myX1 = myBounds[1];
        myY1 = myBounds[0];
        myX2 = myBounds[3];
        myY2 = myBounds[2];
        }
        if(myRange == 0){
        if (myDoCropMarks == true){
        myDrawCropMarks (myBounds[1], myBounds[0], myBounds[3], myBounds[2], myCropMarkLength, myCropMarkOffset, myCropMarkWidth, myRegistrationColor, myNoneSwatch, myLayer);
        }
      
      
        }
        else{
        //Compare the bounds values to the stored bounds.
        //If a given bounds value is less than (for x1 and y1) or 
        //greater than (for x2 and y2) the stored value,
        //then replace the stored value with the bounds value.
        if (myBounds[0] < myY1){
        myY1 = myBounds[0];
        }
        if (myBounds[1] < myX1){
        myX1 = myBounds[1];
        }
        if (myBounds[2] > myY2){
        myY2 = myBounds[2];
        }
        if (myBounds[3] > myX2){
        myX2 = myBounds[3];
        }
        }
        }
        if(myRange != 0){
        if (myDoCropMarks == true){
        myDrawCropMarks (myX1, myY1, myX2, myY2, myCropMarkLength, myCropMarkOffset, myCropMarkWidth,myRegistrationColor, myNoneSwatch, myLayer);
        }
      
      
        }
        myDocument.viewPreferences.rulerOrigin = myOldRulerOrigin;
        //Set the measurement units back to their original state.
        myDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;
        myDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;
      }
      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})
      }
      function myDrawTarget(myBounds, myStrokeWeight, myRegistrationColor, myNoneSwatch, myLayer){
        app.activeWindow.activeSpread.ovals.add(myLayer, undefined, undefined, {strokeWeight:myStrokeWeight, fillColor:myNoneSwatch, strokeColor:myRegistrationColor, geometricBounds:myBounds})
      }
      

       

       

      Advance Thanks,

      K