Answered
Using JSX to add lines between objects
I am trying to createa ascript that places a horizontal line between selected objets. Could someone eyball this and tell me where I'm going wrong?
Thanks
// Get the active document
var myDoc = app.activeDocument;
// Get the selection
var mySelection = myDoc.selection;
// Check if at least two objects are selected
if (mySelection.length < 2) {
alert("Please select at least two objects.");
} else {
// Get the page of the first selected object
var myPage = mySelection[0].parentPage;
// Get the geometric bounds of the selection
var myBounds = mySelection[0].geometricBounds;
for (var i = 1; i < mySelection.length; i++) {
var objBounds = mySelection[i].geometricBounds;
if (objBounds[0] < myBounds[0]) {
myBounds[0] = objBounds[0];
}
if (objBounds[1] < myBounds[1]) {
myBounds[1] = objBounds[1];
}
if (objBounds[2] > myBounds[2]) {
myBounds[2] = objBounds[2];
}
if (objBounds[3] > myBounds[3]) {
myBounds[3] = objBounds[3];
}
}
// Calculate the center of the selection
var myX1 = myBounds[0];
var myY1 = myBounds[1];
var myX2 = myBounds[2];
var myY2 = myBounds[3];
var myCenter = (myY1 + myY2) / 2;
// Add a horizontal line to the page
var myLine = myPage.lines.add({
geometricBounds: [myCenter + "p", "36p", (myCenter + 1) + "p", (myPage.bounds[3] - 36) + "p"],
strokeColor: myDoc.swatches.itemByName("Black"),
strokeWeight: 0.5,
strokeTint: 100,
strokeAlignment: StrokeAlignment.centerAlignment
});
}