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

duplicating one page X times

Community Beginner ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

Hello everyone!

I need a help. I need to duplicate a page X times. Does it means that I want to be able to choose how many times I want to duplicate the page.

I found an interesting script that does it but it duplicate ALL the page of the document while I need to duplicate ONLY the active page. 

I have tried to modify the script but I couldn't.

Can anyone help me?

this is the script I found

 

var n = prompt('Enter a number between 1 and 99.', '', 'Name of dialog');
var reg = /^\d{2}$/;
if (reg.test(n)){
var doc = app.documents[0];
var nbPage = doc.pages.length; // count doc pages

for (i = 0; i < nbPage; i++) {
var sourcePage = doc.pages.item(i + (i*n));
for (j = 0; j < n; j++) {
sourcePage.duplicate(LocationOptions.AFTER, doc.pages.item(i + (i*n)));
}
}
}else{
alert('Error \r Must be a number between 1 to 99');
}

 

TOPICS
How to , Scripting

Views

599

Translate

Translate

Report

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 2 Correct answers

Community Expert , Jan 25, 2021 Jan 25, 2021

Hi,

Try following snippet for duplicating the activePage. Below script, active page will duplicate n times after active page.

var n = prompt('Enter how many times you want to duplicate', '', 'Name of dialog');
var reg = /^\d$/;
if (reg.test(n)) {
    var doc = app.documents[0];
    var activePage = app.layoutWindows[0].activePage

    for (i = 0; i < n; i++) {
        activePage.duplicate(LocationOptions.AFTER, activePage);
    }
} else {
    alert('Error \r Must be a number between 1 to 99');
}

Votes

Translate

Translate
Community Expert , Oct 15, 2024 Oct 15, 2024

Hi @GPGW , You might be better off using the built in InDesign integer dialog field rather than a text prompt, which ensures an integer is entered and returned. Also, you would have to make sure that page shuffling is allowed in order to prevent the new pages being added to a spread—the max number of pages for a spread is 10, which might be triggering the error.

 

Try this:

var n;
var theDialog = app.dialogs.add({name:"Enter a Number", canCancel:true});
with(theDialog.dialogColumns.add()){
    
...

Votes

Translate

Translate
Community Expert ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

Hi,

Try following snippet for duplicating the activePage. Below script, active page will duplicate n times after active page.

var n = prompt('Enter how many times you want to duplicate', '', 'Name of dialog');
var reg = /^\d$/;
if (reg.test(n)) {
    var doc = app.documents[0];
    var activePage = app.layoutWindows[0].activePage

    for (i = 0; i < n; i++) {
        activePage.duplicate(LocationOptions.AFTER, activePage);
    }
} else {
    alert('Error \r Must be a number between 1 to 99');
}
Best regards

Votes

Translate

Translate

Report

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 Beginner ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

it works

thanks

Votes

Translate

Translate

Report

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
Participant ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

Hi,

 

this will generate 1-9 duplicates but 10 and above I get the dialog box about entering a number between 1 and 99.

How can I get it to exceed 9 duplicates? Or should the warning dialogue actually say 'Must be a number between 1 to 9'?

 

Cheers

Votes

Translate

Translate

Report

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 ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

Hi @GPGW , You might be better off using the built in InDesign integer dialog field rather than a text prompt, which ensures an integer is entered and returned. Also, you would have to make sure that page shuffling is allowed in order to prevent the new pages being added to a spread—the max number of pages for a spread is 10, which might be triggering the error.

 

Try this:

var n;
var theDialog = app.dialogs.add({name:"Enter a Number", canCancel:true});
with(theDialog.dialogColumns.add()){
    n = integerEditboxes.add({editValue:1, maximumValue:99, minimumValue:1, minWidth:100});
}
if(theDialog.show() == true){
    n = n.editValue
    theDialog.destroy();
    var doc = app.documents[0];
    //allow page shuffling
    doc.spreads.everyItem().allowPageShuffle = true;
    doc.documentPreferences.properties = {allowPageShuffle:true};
    var activePage = app.layoutWindows[0].activePage
    for (i = 0; i < n; i++) {
        activePage.duplicate(LocationOptions.AFTER, activePage);
    }
}

Votes

Translate

Translate

Report

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
Participant ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

LATEST

Thanks @rob day, I tested this with 11 duplicates and it worked a treat 👌

Votes

Translate

Translate

Report

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 ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

I can't help but ask: why not build a Parent Page?

Mike Witherell

Votes

Translate

Translate

Report

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