Skip navigation
Raul_rubi
Currently Being Moderated

add multiple page

May 28, 2012 4:42 AM

Hi,

 

to see if anyone can help me.

 

I need to define a script, to create multiple pages.

 

at the moment:

 

it is believed only one:

 

the code is this:

 

var myDoc = app.activeDocument;

var myPg = myDoc.pages.item(-1);

var myLastPage = myDoc.pages.add.(LocationOptions.AT_END, myPg);

 

thanks to all !

 
Replies
  • Currently Being Moderated
    May 28, 2012 4:55 AM   in reply to Raul_rubi

    Hi Raul,

     

    Your script is working fine, the error is pages.add.

     

    Raul_rubi wrote:

     

    Hi,

     

    to see if anyone can help me.

    I need to define a script, to create multiple pages.

    at the moment:

    it is believed only one:

    the code is this:

     

    var myDoc = app.activeDocument;

    var myPg = myDoc.pages.item(-1);

    var myLastPage = myDoc.pages.add.(LocationOptions.AT_END, myPg);

     

    thanks to all !

     

    var myDoc = app.activeDocument;
    var myPg = myDoc.pages.item(-1);
    var myLastPage = myDoc.pages.add(LocationOptions.AT_END, myPg);
    

     

     

    thx

    csm_phil

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 5:12 AM   in reply to Raul_rubi

    Hi Rubi,

     

    The problem is you using the period character after the add text before. so this is the problem.

     

    For your information if the anwswer is right please check the right answer otherwise lot of people go and read your thread that is waste of time. please do the process yes or no.

     

    thx

    csm_phil

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 5:17 AM   in reply to Raul_rubi

    Is your problem that thhe script only adds a single page? That's easily fixed.

    By the way, if you use AT_END you don't need to supply an additional pointer, the new page will always end up there.

     

    Untested but this ought to work:

     

    var myDoc = app.activeDocument;

    var addPages = 6;

    // Save first added page ...

    var myFirstAddedPage = myDoc.pages.add(LocationOptions.AT_END);

    addedPages--;

    while (addPages > 0)

    {

       addPages--;

       myDoc.pages.add(LocationOptions.AT_END);

    }

     

    ..  'myFirstAddedPage' will point to the first one of your newly added pages.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 5:20 AM   in reply to csm_phil

    > The problem is you using the period character after the add text before. so this is the problem.

     

    Hah -- I saw that in my code and thought, "huh why did I do *that*!?" (I copied a part of the original.)

     

    Raul, it would have helped if you told us *why* your code failed! The error message would have indicated this mistake right away.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 7:23 AM   in reply to Raul_rubi

    Raul_rubi wrote:

    I can not create multiple pages

     

    Please tell us why not! Help us to help you!

     

    But, I'm back behind my computer so let's see what's wrong. Running my script now -- oops.

     

    -----------------------------

    JavaScript Error!

     

    Error Number: 2

    Error String: addedPages is undefined

     

    File: ...

    Line: 5

    Source: addedPages--;

    -----------------------------

     

    Well, that's pretty clear. I mis-typed 'addedPages' on that line, it should have been 'addPages'. With that corrected, the script does indeed add 6 empty pages at the end of my current document.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 8:19 AM   in reply to Raul_rubi

    That's different from what I understood from your original post, but ... still no problem. Instead of AT_END, which does what it says, use AFTER (this *also* does what it says):

     

    var myDoc = app.activeDocument;
    var addPages = 6;
    // Page number 2 is item(1), since page number 1 is item(0):
    var addAfter = app.activeDocument.pages.item(1);
    // Save first added page ...
    var myFirstAddedPage = myDoc.pages.add(LocationOptions.AFTER, addAfter);
    addPages--;
    // .. then add the others AFTER it as well
    while (addPages > 0)
    {
       addPages--;
       myDoc.pages.add(LocationOptions.AFTER, myFirstAddedPage);
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 8:48 AM   in reply to [Jongware]

    You type too quickly jong although I did do it slightly different…

     

    app.activate();
    var myDoc = app.activeDocument;
    var midPage = myDoc.pages.middleItem(); // some middle ref
    var addPages = 6;
    do { 
        myDoc.pages.add( LocationOptions.AFTER, midPage );
        addPages--;
    } while ( addPages > 0 )
    

     

    Just edited that app.activate which was clearly wrong… needed ()

     
    |
    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