Skip to main content
Inspiring
February 16, 2023
Answered

adding guides to the first page

  • February 16, 2023
  • 1 reply
  • 1011 views

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();
  }

 

This topic has been closed for replies.
Correct answer brian_p_dts

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

1 reply

Inspiring
February 16, 2023

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}); 

 

Inspiring
February 16, 2023

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});
    }

 

brian_p_dts
brian_p_dtsCorrect answer
Adobe Expert
February 16, 2023

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