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

[basiljs] remove all pages except one

Community Beginner ,
May 22, 2013 May 22, 2013

In a script i create pages, export to pdf, remove pages and then create again etc.

At the moment i use this:

for(var j = b.pageCount(); j > 1; j--) {

          b.removePage(j);

}

But it is really slow. I think indesign does a lot of calculating after removing a page (due link textfields) so it would be more efficient to remove all the pages at once.

Now my question is how can i do that?

I tested and if i delete about 5500 empty pages with the script it takes around 8 minutes.

If i select them all in indesign and then delete it takes around 10 seconds.

Another way to speed up a litle is to clear all the content. It will still take long but probably a bit faster.

Thing is i have

b.clear(b.doc());

but this remove the master page as well and i need to keep the master page.

In short, how can i remove all pages (except one since indesign needs one page) at once?

TOPICS
Scripting
1.3K
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

Contributor , May 22, 2013 May 22, 2013

Hi,

i do removing many pages in indesign with

  • use documentPreferences.pagesPerDocument (faster)
  • use while or for loop
  • close doc without saving, and open again. (in some case)

here is test code, run with old Macbook Air + CS5 + OSX10.7

var pp = function (args) {

  $.writeln(args);

}

var remove_all_pages_use_pref = function (doc) {

  pp("start deleting (use preferences)");

  $.hiresTimer;

  doc.documentPreferences.pagesPerDocument = 1;

  pp("end deleting");

  pp($.hiresTimer);

}

var remove_all_pages_use_loop = f

...
Translate
Contributor ,
May 22, 2013 May 22, 2013

Hi,

i do removing many pages in indesign with

  • use documentPreferences.pagesPerDocument (faster)
  • use while or for loop
  • close doc without saving, and open again. (in some case)

here is test code, run with old Macbook Air + CS5 + OSX10.7

var pp = function (args) {

  $.writeln(args);

}

var remove_all_pages_use_pref = function (doc) {

  pp("start deleting (use preferences)");

  $.hiresTimer;

  doc.documentPreferences.pagesPerDocument = 1;

  pp("end deleting");

  pp($.hiresTimer);

}

var remove_all_pages_use_loop = function (doc) {

  var i = doc.pages.length;

  pp("start deleting (while --)");

  $.hiresTimer;

  while (i--) {

    if (i==1) {break;}

    doc.pages.remove();

  }

  pp("end deleting");

  pp($.hiresTimer);

}

function main() {

  var doc = app.documents.add();

  $.hiresTimer;

  doc.documentPreferences.pagesPerDocument = 5500;

  pp('# create 5500 pages');

  pp($.hiresTimer);

  var indd = new File("~/Desktop/5500.indd");

  doc.save(indd);

  pp("------------");

  remove_all_pages_use_pref(doc);

  doc.close(SaveOptions.NO);

  pp("------------");

  pp("# try another way");

  var doc2 = app.open(indd);

  remove_all_pages_use_loop(doc2);

  doc2.close(SaveOptions.NO);

}

main();

result

# create 5500 pages
30395026
------------
start deleting (use preferences)
end deleting
28215999
------------
# try another way
start deleting (while --)
end deleting
268641063

thanks

mg

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 Beginner ,
May 22, 2013 May 22, 2013

looks promosing!

How can i do this on the current document?

I tried:

    var doc = app.documents.current();

And i did found a html reference for indesign but if i did a search on app i had more then 500 hits and the same for document so that wasn't really helping.

thanks

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
LEGEND ,
May 22, 2013 May 22, 2013

var doc = app.activeDocument should do it.

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 Beginner ,
May 22, 2013 May 22, 2013
LATEST

thanks!

so in short:

var doc = app.activeDocument;

doc.documentPreferences.pagesPerDocument = 1;

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