Highlighted

Delete pages or Extract pages from an Indesign document

Participant ,
Apr 11, 2019

Copy link to clipboard

Copied

I need to delete pages from a 40 page Indesign document (i.e. pages 2-13, 15-26, 28-39)

I'm not sure if it can be done but would like to know for sure.
If it's easier to extract the pages required into a new document I'm happy with that option too.

I've used this script but it only does 1 range (2-13) as far as I can see.

Any help would be greatly appreciated.

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

  

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() {

  range_test = number_pages.indexOf("-");

  if (range_test != -1) {

  split_range = number_pages.split("-");

  start = split_range[0];

  end = split_range[1];

  number = parseInt(end) - parseInt(start) + 1;

  for (i=0; i<number; i++) {

  page = parseInt(end) - i;

  page = page + "";

  app.activeDocument.pages.item(page).remove();

  }

  } else {

  app.activeDocument.pages.item(number_pages).remove();

  }

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }

}

Hi Manan,

Thanks for your reply.


I've isolated the problem to the master pages and I'm looking at it now. When I override the master page elements it works perfectly well. The test file I sent wasn't a production job and had no master page elements to consider.

For anyone who needs it, the script was used in a mail merge document to isolate individual pages in a 148-page document:
(pages: 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148), removing the rest.

Before running the script a few things to check:

Disable Enable in Layout View & Enable in Stroy editor (Indesign/Preferences/Type/Drag and Drop Test Editing).
If multiple master pages, you may need to override as mentioned above.

Run the script and add the unwanted pages into the dialogue box e.g.:

pages 2-12, 14-24, 26-36, 38-49, 51-61, 63-73, 75-85, 87-98, 100-110, 112-122, 124-134, 136-147


This will then process leaving only 13 pages in the document:
pages 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148

Thanks for all your help with this…

————————————————————————————

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

 

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() 

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(","); 

    var pg = app.activeDocument.pages.everyItem().getElements() 

    for (i=0; i<range_test.length; i++) 

    { 

          pg[parseInt(range_test) - 1].remove(); 

    } 

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }}

————————————————————————————

TOPICS
Scripting

Views

1.1K

Likes

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

Delete pages or Extract pages from an Indesign document

Participant ,
Apr 11, 2019

Copy link to clipboard

Copied

I need to delete pages from a 40 page Indesign document (i.e. pages 2-13, 15-26, 28-39)

I'm not sure if it can be done but would like to know for sure.
If it's easier to extract the pages required into a new document I'm happy with that option too.

I've used this script but it only does 1 range (2-13) as far as I can see.

Any help would be greatly appreciated.

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

  

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() {

  range_test = number_pages.indexOf("-");

  if (range_test != -1) {

  split_range = number_pages.split("-");

  start = split_range[0];

  end = split_range[1];

  number = parseInt(end) - parseInt(start) + 1;

  for (i=0; i<number; i++) {

  page = parseInt(end) - i;

  page = page + "";

  app.activeDocument.pages.item(page).remove();

  }

  } else {

  app.activeDocument.pages.item(number_pages).remove();

  }

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }

}

Hi Manan,

Thanks for your reply.


I've isolated the problem to the master pages and I'm looking at it now. When I override the master page elements it works perfectly well. The test file I sent wasn't a production job and had no master page elements to consider.

For anyone who needs it, the script was used in a mail merge document to isolate individual pages in a 148-page document:
(pages: 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148), removing the rest.

Before running the script a few things to check:

Disable Enable in Layout View & Enable in Stroy editor (Indesign/Preferences/Type/Drag and Drop Test Editing).
If multiple master pages, you may need to override as mentioned above.

Run the script and add the unwanted pages into the dialogue box e.g.:

pages 2-12, 14-24, 26-36, 38-49, 51-61, 63-73, 75-85, 87-98, 100-110, 112-122, 124-134, 136-147


This will then process leaving only 13 pages in the document:
pages 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148

Thanks for all your help with this…

————————————————————————————

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

 

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() 

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(","); 

    var pg = app.activeDocument.pages.everyItem().getElements() 

    for (i=0; i<range_test.length; i++) 

    { 

          pg[parseInt(range_test) - 1].remove(); 

    } 

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }}

————————————————————————————

TOPICS
Scripting

Views

1.1K

Likes

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
Apr 11, 2019 1
Most Valuable Participant ,
Apr 11, 2019

Copy link to clipboard

Copied

See set conditional text  – scroll down to my answer for a short snippet that uses a custom replace function to change any from-to range in a comma separated list. Works with multiple ranges as well; it might be all you need.

Likes

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
Reply
Loading...
Apr 11, 2019 0
Participant ,
Apr 12, 2019

Copy link to clipboard

Copied

Thank you for your reply
I've tried inserting your snippet into my code but I'm not having much luck!

Where about should I be inserting your code?

Thanks again

Likes

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
Reply
Loading...
Apr 12, 2019 0
Adobe Community Professional ,
Apr 13, 2019

Copy link to clipboard

Copied

Replace your method definition of pages_remove with the following

function pages_remove()

{

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(",");

    var pg = app.activeDocument.pages.everyItem().getElements()

    for (i=0; i<range_test.length; i++)

    {

          pg[parseInt(range_test) - 1].remove();

    }

}

-Manan

Likes

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
Reply
Loading...
Apr 13, 2019 0
Community Beginner ,
Apr 25, 2019

Copy link to clipboard

Copied

Thanks for the script, much appreciated.

I ran the updated script and ran it on a 12 page blank Indesign document. If I select remove pages 5-7 they are not removed and a further 15 pages are added to the document?

Below is the modified script I'm using I'm using:

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

 

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  } } }

  }

  return dialoog_venster;

}

function pages_remove() 

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(","); 

    var pg = app.activeDocument.pages.everyItem().getElements() 

    for (i=0; i<range_test.length; i++) 

    { 

          pg[parseInt(range_test) - 1].remove(); 

    } 

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }}}}

}

Any help would be much appreciated.

Likes

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
Reply
Loading...
Apr 25, 2019 0
Adobe Community Professional ,
Apr 25, 2019

Copy link to clipboard

Copied

Hi,

Using the code above working as expected for me, was able to remove pages 5-7, and ended up with a 9 page document.

Ran using the ExtendScript debugger for Visual Studio Code. (just in case you are using another method)

Regards

Malcolm

Likes

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
Reply
Loading...
Apr 25, 2019 1
Adobe Community Professional ,
Apr 25, 2019

Copy link to clipboard

Copied

Hi Mike,

best use the Advanced Editor option of the forum editor.

Then you could format your code as code.

1. Select your code.

2. Go to Insert >> Syntax Highlighting > javascript

3. Done.

( You have to scroll down a bit to find "javascript" when in Syntax Highlighting )

Regards,
Uwe

Likes

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
Reply
Loading...
Apr 25, 2019 1
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

Thanks Mani,

Appreciate the help and advice.

I’ve posted my comments on the forum but have attached my document here as I’m still getting the same results. I’m using Indesgn 2019.

Cheers,

Mike

Likes

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
Reply
Loading...
Apr 26, 2019 0
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

Thanks for the info, appreciate the advice.


I'm still getting the same result as described below.
1. My start point is a 12 page document:
Screen Shot 2019-04-26 at 08.45.07.png

2. Script runs and asks for pages to be removed:
Screen Shot 2019-04-26 at 08.45.31.png

3. The result is no pages have been removed (5-7) and there are now 20 and not 9 pages as required.

Screen Shot 2019-04-26 at 08.45.59.png

This test job is a forerunner to a regular 550+ page data merge I am doing.
I've sent the indesign file via email

Cheers

Likes

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
Reply
Loading...
Apr 26, 2019 0
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Mike,

what exactly is returned after you pressed the OK button?

Can you catch and debug this?

Should be the string:

"5-7"

Set some breakpoints in your script and debug it step by step using the ESTK so you could see where it fails.

Regards,
Uwe

Likes

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
Reply
Loading...
Apr 26, 2019 0
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

Thanks for the quick reply, much appreciated.

I've run the debugger step by step and after executing the OK button the extra pages are added at line 14 pages_remove();

The console is not indicating any errors.

I'll mail you the files. If you don't get the same result then it suggests that there is something wrong with my system.

Likes

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
Reply
Loading...
Apr 26, 2019 0
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Mike,

As BarlaeDC​ mentioned i also got the script working fine on my end. Have a look at the gif on what happens on my end, i just copied and pasted your final code and ran it on a 12 page document. I used InDesign CC 14.0.1

Do you have any other script or plugin working along with this script? Disable them and then try. Also could you post your InDesign file here on the forum. upload it to Dropbox, Google drive or any other cloud service and share the public access link here.

Demo.gif

-Manan

Likes

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
Reply
Loading...
Apr 26, 2019 0
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

This is the link to my test Indesign file. Dropbox - Carl page.indd - Simplify your life
This is a link showing what I get when run it:

https://www.dropbox.com/s/achh5lfk7kvkvep/test%20recording.mov?dl=0

I'm on a mac,

Likes

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
Reply
Loading...
Apr 26, 2019 0
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Mike,

Look at the video that you sent, once you run the script focus on the page panel it shows that the pages have changed to 9 and then Extendscript comes to focus and then after sometime the pages are added and become 20. Seems some other code is also active in your InDesign that is adding the pages, the script under question works fine as i can see.

-Manan

Likes

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
Reply
Loading...
Apr 26, 2019 0
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Manan,

That's very strange, I'm only running this script, I'm sure of that! I wonder if it's a Mac thing?
The data I provided is all I'm using (Dropbox - Carl page.indd - Simplify your life)

Likes

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
Reply
Loading...
Apr 26, 2019 0
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

The issue is with the Smart Text Reflow, switch it off and then try. To switch it off go to Preferences>Type>Smart Text Reflow

-Manan

Likes

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
Reply
Loading...
Apr 26, 2019 3
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

You are calling removeOverride method, this will also result in addition of pages as once the override is removed the content will be overset in the threaded text frames you have on your pages and hence Smart Text Reflow will trigger a page add.

-Manan

Likes

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
Reply
Loading...
Apr 26, 2019 2
Community Beginner ,
Apr 26, 2019

Copy link to clipboard

Copied

Turning off the smart text reflow has fixed the creation of extra pages.
Using the default script 'SplitStory.jsx', before I ran my script, prevented the overset in the threaded text frames on my pages. I can't see any other way of keeping the text on the page on reflection.

So a big thank you for all your help, this will be used a lot!

Likes

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
Reply
Loading...
Apr 26, 2019 0
Participant ,
Jun 03, 2019

Copy link to clipboard

Copied

Hi All,

I've been testing the script now for the past few weeks, though it's been working great we've hit a snag.

The script seems to work great with documents that have one master page. But it seems to screw up if there are several master pages (i.e. B, C, D etc)

Is this something that is doable? Below is the script that works fine with just one master page

var order="2-13, 15-26, 28-39, 1, 14, 27 ,40, 41-45";

// Create an array out of the list:

ranges = toSeparate (order);

if (ranges.length != app.activeDocument.pages.length)

{

alert ("Page number mismatch -- "+ranges.length+" given, "+app.activeDocument.pages.length+" in document");

exit(0);

}

// Consistency check:

sorted = ranges.slice().sort(numericSort);

for (a=0; a<sorted.length-1; a++)

{

if (sorted < sorted[a+1]-1 ||

  sorted == sorted[a+1])

  alert ("Mismatch from "+sorted+" to "+sorted[a+1]);

}

// alert ("New order for "+order+"\nis "+ranges.join(", "));

// Convert from 1..x to 0..x-1:

for (moveThis=0; moveThis<ranges.length; moveThis++)

ranges[moveThis]--;

for (moveThis=0; moveThis<ranges.length; moveThis++)

{

if (moveThis != ranges[moveThis])

{

  try{

   app.activeDocument.pages[ranges[moveThis]].move (LocationOptions.BEFORE, app.activeDocument.pages[moveThis]);

  } catch(_) { alert ("problem with page "+moveThis+"/index "+ranges[moveThis]); }

}

for (updateRest=moveThis+1; updateRest<ranges.length; updateRest++)

  if (ranges[updateRest] < ranges[moveThis])

   ranges[updateRest]++;

}

function toSeparate (list)

{

s = list.split(",");

for (l=0; l<s.length; l++)

{

  try {

  if (s.indexOf("-") > -1)

  {

   indexes = s.split("-");

   from = Number(indexes[0]);

   to = Number(indexes[indexes.length-1]);

   if (from >= to)

   {

    alert ("Cannot create a range from "+from+" to "+to+"!");

    exit(0);

   }

   s = from;

   while (from < to)

    s.splice (++l,0,++from);

  }} catch(_){}

}

// s.sort (numericSort);

return s;

}

function numericSort(a,b)

{

return Number(a) - Number(b);

}

//–––––––––––––––––––––––––––––––––––––

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

 

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() {

  range_test = number_pages.indexOf("-");

  if (range_test != -1) {

  split_range = number_pages.split("-");

  start = split_range[0];

  end = split_range[1];

  number = parseInt(end) - parseInt(start) + 1;

  for (i=0; i<number; i++) {

  page = parseInt(end) - i;

  page = page + "";

  app.activeDocument.pages.item(page).remove();

  }

  } else {

  app.activeDocument.pages.item(number_pages).remove();

  }

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }

}

Likes

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
Reply
Loading...
Jun 03, 2019 0
Adobe Community Professional ,
Jun 03, 2019

Copy link to clipboard

Copied

Can you be specific, i did run your code and it seemed to work just fine when i have 2 or more master pages. Please provide more details on whether you get an error or if the operations done by the code are not what you want it to do.

Also the code discussed and verified to be working in this thread seems to be different from the code you have. Did you try the code that's reported in the thread to be working, if not then what extra are you trying to achieve in your code?

-Manan

Likes

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
Reply
Loading...
Jun 03, 2019 0
Participant ,
Jun 05, 2019

Copy link to clipboard

Copied

Hi Manan,

Thanks for your reply.


I've isolated the problem to the master pages and I'm looking at it now. When I override the master page elements it works perfectly well. The test file I sent wasn't a production job and had no master page elements to consider.

For anyone who needs it, the script was used in a mail merge document to isolate individual pages in a 148-page document:
(pages: 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148), removing the rest.

Before running the script a few things to check:

Disable Enable in Layout View & Enable in Stroy editor (Indesign/Preferences/Type/Drag and Drop Test Editing).
If multiple master pages, you may need to override as mentioned above.

Run the script and add the unwanted pages into the dialogue box e.g.:

pages 2-12, 14-24, 26-36, 38-49, 51-61, 63-73, 75-85, 87-98, 100-110, 112-122, 124-134, 136-147


This will then process leaving only 13 pages in the document:
pages 1, 13, 25, 37, 50, 62, 74, 86, 99, 111, 123, 135, 148

Thanks for all your help with this…

————————————————————————————

if (app.documents.length == 0){

  alert("There is no document open to delete pages.");

  exit();

}

var remove_pages = menu();

if (remove_pages.show()) {

number_pages = pages.editContents;

  try {

  remove_override();

  pages_remove();

  } catch (e) {}

}

//functions

//--------------------------------------------------------------------

function menu(){

var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );

  with (dialoog_venster){

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  with (dialogRows.add() ){

  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );

  }

  }

  with (dialogRows.add() ){

 

  with (dialogColumns.add() ){

  with (dialogRows.add() ){

  pages = textEditboxes.add({editContents:"", minWidth:225} ); }

  }

  }

  }

  }

  return dialoog_venster;

}

function pages_remove() 

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(","); 

    var pg = app.activeDocument.pages.everyItem().getElements() 

    for (i=0; i<range_test.length; i++) 

    { 

          pg[parseInt(range_test) - 1].remove(); 

    } 

}

function remove_override() {

  total_number_pages = app.activeDocument.pages.length;

  for (i=1; i<total_number_pages; i++) {

  page_items = app.activeDocument.pages.item(i).pageItems;

  for (j=page_items.length-1; j>-1; j--) {

  if (page_items.label == "") {

  if (page_items.overridden == true) {

  page_items.removeOverride();

  }

  }

  }

  }}

————————————————————————————

Likes

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
Reply
Loading...
Jun 05, 2019 0
Community Beginner ,
May 17, 2020

Copy link to clipboard

Copied

Hi,

 

I was hoping someone might have a solution to the below:

 

I've tried to use this script, when I run it the dialog box opens and I can enter page ranges however when I run it, nothing happens.

 

When I run the script via extenscript toolkit, it tells me: 

Result: undefined

 

I'm running Indesign CC 2020 and MacOS Mojave.

 

Many thanks

Matt 

 

Likes

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
Reply
Loading...
May 17, 2020 0
Adobe Community Professional ,
May 18, 2020

Copy link to clipboard

Copied

Hi Matt,

did you recently copy the code from this thread to the ESTK or a different editor?

If so it could be that all this posted code here in the thread is "corrupt".

Means: The code has changed in subtle or not so subtle ways when moving this thread to the new Adobe InDesign Forum last year.

 

Let's hope that the the original poster, MadMich, will stop by and will correct the now presented code.

 

That mess happened to a lot with old threads, pre September 2019, presenting ExtendScript code:

InDesign, Illustrator, PhotoShop and other Adobe forums.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
May 18, 2020 0
Advisor ,
May 18, 2020

Copy link to clipboard

Copied

Original code (from my email subscription) 

if (app.documents.length == 0){
  alert("There is no document open to delete pages.");
  exit();
}
 
var remove_pages = menu();
 
if (remove_pages.show()) {
number_pages = pages.editContents;
  try {
  remove_override();
  pages_remove();
  } catch (e) {}
}
 
//functions
//--------------------------------------------------------------------
function menu(){
var dialoog_venster = app.dialogs.add({name:"Delete pages", canCancel:true} );
  with (dialoog_venster){
  with (dialogColumns.add() ){
  with (dialogRows.add() ){
  with (dialogRows.add() ){
  staticTexts.add({staticLabel:"Pagerange you want to delete:       "} );
  }
  }
 
  with (dialogRows.add() ){
 
  with (dialogColumns.add() ){
  with (dialogRows.add() ){
  pages = textEditboxes.add({editContents:"", minWidth:225} ); }
  }
  }
 
  }
 
  }
  return dialoog_venster;
}
 
function pages_remove() 
{ 
    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(","); 
    var pg = app.activeDocument.pages.everyItem().getElements() 
    for (i=0; i<range_test.length; i++) 
    { 
          pg[parseInt(range_test[i]) - 1].remove(); 
    } 
}
 
function remove_override() {
  total_number_pages = app.activeDocument.pages.length;
  for (i=1; i<total_number_pages; i++) {
  page_items = app.activeDocument.pages.item(i).pageItems;
  for (j=page_items.length-1; j>-1; j--) {
  if (page_items[j].label == "") {
  if (page_items[j].overridden == true) {
  page_items[j].removeOverride();
  }
  }
  }
 
  }}

 

Likes

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
Reply
Loading...
May 18, 2020 2
Community Beginner ,
May 18, 2020

Copy link to clipboard

Copied

Thank you both

 

The above original code has resolved the issue and the script now works.

Likes

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
Reply
Loading...
May 18, 2020 0