Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

adding guides to the first page

Engaged ,
Feb 15, 2023 Feb 15, 2023

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

 

TOPICS
Scripting
987
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 15, 2023 Feb 15, 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

Translate
Engaged ,
Feb 15, 2023 Feb 15, 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}); 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 15, 2023 Feb 15, 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});
    }

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2023 Feb 15, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 16, 2023 Feb 16, 2023

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();
  }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 16, 2023 Feb 16, 2023
LATEST

I see, I was using guideOrientation instead of just orientation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines