Skip navigation
Currently Being Moderated

inserting blank page for ads according to datamerged field.checking for whether a variable exists on

Jul 11, 2012 1:18 PM

Tags: #on #a #for #variable #page #within #exists #loop. #checking #whether

Let me see if I can explain what I am trying to do. I have a script which loops through pages of an indesign document. I use a for loop to do so.

 

Within each page is a text frame called "Advertising" with a Y or N as the value. If the value is Y, I want to insert a blank page before the page with the advertising field. Within the for loop however, there are calls to other data fields. My issue is that when I add a blank page, and the for loop continues, it errs out because the blank page does not contain the variable fields I am using. (highlights)...

 

So my question is, how can I cause the for loop to skip the newly inserted page so that the missing variable doesn't cause the script to fail?

 

should I be checking whether the layer exists then doing something like:

if(newDoc.pages.item(i).pageItems.item("CompanyHighlights").length > 0){}

 

 

for(var i = o; i < PageLength-1; i++){

 

//some kind of check to determine whether it's a blank page, or a page with the variable.

     if(newDoc.pages.item(i).pageItems.item("CompanyHighlights").length > 0){

         

          var highlights= newDoc.pages.item(i).pageItems.item("CompanyHighlights").contents;

 

          var advertising = newDoc.pages.item(i).pageItems.item("Advertising").contents;

          if(advertising == "Y")

          {

               //add blank page before this page

          }

 

     }

}

 
Replies
  • Currently Being Moderated
    Jul 11, 2012 2:54 PM   in reply to caseyctg

    hi,

     

    try the loop backwards ...

     

    var myPages = app.activeDocument.pages;

     

    for(var i = myPages.length -1; i >= 0; i--){

    app.activeDocument.pages.add(LocationOptions.BEFORE, myPages[i]);

     

        }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points