Can anyone let me know what's wrong with my script for generating 3 rectangle objects?
Greetings,
I'm trying to acheive the following algorythm
Write a javascript for Adobe InDesign that will do the following:
Step 1: Make dialogue box pop up for the user to enter a value for "finished width" in inches, "finished height" in inches and "bleed" in inches
Step 2: The user press an OK button on the dialogue box
Step 3. A new document is created with "document width" equal to "finished width" plus two times "bleed" and "document height" equal to "finished height" plus two times "bleed"
Step 4: Create a rectangle object named "Bleed" with width equal to "document width", and height equal to "document height", and stroke equal to 0, and fill equal to RED, and transparency equal to 50 percent, and place it centered on the page, and align stroke to inside
Step 5: Create a rectangle object named "Finished Size" with width equal to "finished width", and height equal to "finished height", and linetype equal to DASHED, and stroke equal to 10pt, and stroke color equal to BLACK, and fill color equal to NONE, and transparency equal to 100 percent, and place it centered on the page
Step 6: Create a rectangle object named "Safe Area" with width equal to "finished width" minus 2, and height equal to "finished height" minus 2, and linetype equal to SOLID, and stroke equal to 5pt, and stroke color equal to GREEN, and fill color equal to NONE, and transparency equal to 100 percent, and place it centered on the page
and I have this script, but it just crashes InDesign after entering the values into the dialogue box.
// Prompt the user to enter the finished width, finished height, and bleed values
var finishedWidthIN = prompt("Enter the finished width (inches):");
var finishedHeightIN = prompt("Enter the finished height (inches):");
var bleedIN = prompt("Enter the bleed (inches):");
// Convert the entered values to points (1 inch = 72 points)
finishedWidth = finishedWidthIN * 72;
finishedHeight = finishedHeightIN * 72;
bleed = bleedIN * 72;
// Create a new document with the calculated dimensions
var doc = app.documents.add({
documentPreferences: {
pageWidth: finishedWidth + (2 * bleed),
pageHeight: finishedHeight + (2 * bleed)
}
});
// Create the Bleed rectangle
var bleedRect = doc.pages.item(0).rectangles.add({
geometricBounds: [0, 0, doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth],
strokeWeight: bleed,
fillColor: "Red",
transparencySettings: { blendingSettings: { opacity: 50 } },
strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT
});
// Create the Finished Size rectangle
var finishedRect = doc.pages.item(0).rectangles.add({
geometricBounds: [(doc.documentPreferences.pageHeight - finishedHeight) / 2, (doc.documentPreferences.pageWidth - finishedWidth) / 2, (doc.documentPreferences.pageHeight + finishedHeight) / 2, (doc.documentPreferences.pageWidth + finishedWidth) / 2],
strokeWeight: 10,
strokeColor: "Black",
strokeType: [DashedStroke()],
fillColor: "None",
transparencySettings: { blendingSettings: { opacity: 100 } }
});
// Create the Safe Area rectangle
var safeAreaRect = doc.pages.item(0).rectangles.add({
geometricBounds: [(doc.documentPreferences.pageHeight - (finishedHeight - 2)) / 2, (doc.documentPreferences.pageWidth - (finishedWidth - 2)) / 2, (doc.documentPreferences.pageHeight + (finishedHeight - 2)) / 2, (doc.documentPreferences.pageWidth + (finishedWidth - 2)) / 2],
strokeWeight: 5,
strokeColor: "Green",
strokeType: [SolidStroke()],
fillColor: "None",
transparencySettings: { blendingSettings: { opacity: 100 } }
});
Please let me know if you can find what's causing it to crash. Thank you much!!!!
