Copy link to clipboard
Copied
I'm trying to add guides to the first page but it's not working. Anyone know what I'm doing wrong here?
function createDocument(documentWidth, documentHeight, bleed) {
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
var doc = app.documents.add({
documentPreferences: {
pageWidth: documentWidth,
pageHeight: documentHeight,
documentBleedTopOffset: bleed,
documentBleedUniformSize: true,
facingPages: false
}
});
//Set the rulers to inches
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
// Add 2 pages to the document
for (var i = 0; i < 2; i++) {
doc.pages.add();
}
// Add guides to the first page
var page = doc.pages.item(0);
page.guides.add(HorizontalOrVertical.HORIZONTAL, 49);
page.guides.add(HorizontalOrVertical.HORIZONTAL, 751);
page.guides.add(HorizontalOrVertical.VERTICAL, 600);
page.guides.add(HorizontalOrVertical.VERTICALL, 648.75);
page.guides.add(HorizontalOrVertical.VERTICAL, 900);
}
if (checkbox1.value == true) {
createDocument(1200, 800, 9);
} else {
exit();
}
Guides.add only takes two arguments. You have three in your later examples. So it's... .add(undefined, {props});
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Guides.html#d1e264386__d1e264435
Copy link to clipboard
Copied
Well I'm closer but now I only end up with the last guide and none of the others.
page.guides.add(undefined, undefined, {itemLayer: page, guideOrientation: HorizontalOrVertical.HORIZONTAL, location: 49});
page.guides.add(undefined, undefined, {itemLayer: page, guideOrientation: HorizontalOrVertical.HORIZONTAL, location: 751});
page.guides.add(undefined, undefined, {itemLayer: page, guideOrientation: HorizontalOrVertical.VERTICAL, location: 600});
page.guides.add(undefined, undefined, {itemLayer: page, guideOrientation: HorizontalOrVertical.VERTICAL, location: 648.75});
page.guides.add(undefined, undefined, {itemLayer: page, guideOrientation: HorizontalOrVertical.VERTICAL, location: 900});
Copy link to clipboard
Copied
So I tried a loop and it still only shows the last guide.
var guideLocations = [49, 751, 600, 648.75, 900];
for (var i = 0; i < guideLocations.length; i++) {
var location = guideLocations[i];
var newGuide = myPage.guides.add(undefined, undefined, {itemLayer: myPage, guideOrientation: HorizontalOrVertical.HORIZONTAL, location: location});
}
Copy link to clipboard
Copied
Guides.add only takes two arguments. You have three in your later examples. So it's... .add(undefined, {props});
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Guides.html#d1e264386__d1e264435
Copy link to clipboard
Copied
Ok, so I'm only trying to get the horizontal guides first. I can get two guides on the first page now but they keep showing up vertical instead of horizontal. Any idea why?
function createDocument(documentWidth, documentHeight, bleed) {
// Create a new document with the specified width and height and bleed
var doc = app.documents.add({
documentPreferences: {
pageWidth: documentWidth,
pageHeight: documentHeight,
documentBleedTopOffset: bleed,
documentBleedUniformSize: true,
facingPages: false
}
});
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
// Add 3 pages to the document
for (var i = 0; i < 2; i++) {
doc.pages.add();
}
var firstPage = doc.pages.item(0);
var guideLocations = [49, 751];
// Loop through the guide locations and add guides to the first page
for (var i = 0; i < guideLocations.length; i++) {
var location = guideLocations[i];
var props = {
guideOrientation: HorizontalOrVertical.HORIZONTAL,
location: location
};
var newGuide = firstPage.guides.add(undefined, props);
}
}
if (checkbox1.value == true) {
createDocument(1200, 800, 9);
} else {
exit();
}
Copy link to clipboard
Copied
I see, I was using guideOrientation instead of just orientation.