Search code examples
javascriptadobe-indesign

Create a GraphicLine using InDesign JS based on Page Size withn the Geometric Bounds


My overall goal is to create crop marks with specific specifications. I have tried manipulating the supplied sample script that comes with InDesign to no ends. I am now trying to create my own crop marks and working to fully understand the geometric aspects of using the graphicLine feature.

Below is what I have thus far:

var myCropMarkLength = 15.12;
var myCropMarkOffset = 20.88;
var myCropMarkWidth = .25;
var myX1 = ([myDocument.documentPreferences.pageHeight - myDocument.documentPreferences.pageHeight]);
var myY1 = ([myDocument.documentPreferences.pageWidth - myDocument.documentPreferences.pageWidth]);
var myX2 = ([myDocument.documentPreferences.pageHeight]);
var myY2 = ([myDocument.documentPreferences.pageWidth]);
myOutsideGuide_Left = app.activeDocument.pages[0].graphicLines.add ();
myOutsideGuide_Left.geometricBounds = [myX1, myY1, myX2, myY2 ];
myOutsideGuide_Left.strokeWeight = myCropMarkWidth;

If anyone could help me be able to fill in the myX1, myY1, myX2, myY2 that would be wonderful. I am sure that I am missing something, but I should be able to reference the page size within the coordinates as this is how the coordinates are determined.

Best, John


Solution

  • I didn't want to use the CropMarks.JSX script because it would require me to create a rectangle each time I work on a document. I am also trying to build a script that can be applied to all my art files on a regular basis and shared with my team internally. This would allow consistency across all of the artwork, from the crop mark length, offset amount, and stroke weight. I also want the crop marks to be based on page height and width.

    I have been able to develop the crop marks using the below script.

    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;
    

    One of my largest issues when creating this script was determine that the bounds are [Y1,X1,Y2,X2] This was backwards from what I thought they would have been.

    Hope that this code helps others in creating crop marks based on page size, but cannot use the InDesign Crop Mark method based on workflows being used.