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

Pages added by scripting create new spread, why?

Explorer ,
Aug 14, 2016 Aug 14, 2016

Hello,

       I'm working on a method that will add a page, add some content to that page, then repeat.  Sometimes, depending on how I arrange my code, the new pages are added within the current spread, sometimes adding a new page automatically creates a new spread.  How do I control this?

From my testing thus far, having

var mySpread = MyDocument.spreads.add();

before

myPage = mySpread.pages.add();

But if I don't add a new spread before adding a page it seems to create the new page within the current spread.

It seems like there should be some way to control what spread pages are added to, and whether or not adding a page automatically creates a new spread?  Thanks for any help.

TOPICS
Scripting
2.1K
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 Expert ,
Aug 14, 2016 Aug 14, 2016

That is because you are manipulating spreads. To just add 'any' page to a document, add it directly to the document.pages object. That way it will work exactly like in the interface: it only adds another spread when the current one is 'full' according to its master spread.

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
Explorer ,
Aug 14, 2016 Aug 14, 2016

Hmmm, I tried changing the code to:

var mySpread = myDocument.spreads.add();

myPage = myDocument.pages.add();

But the new page is added to a new spread, not the just-created mySpread.  I also tried adding more pages to my master spread, but that didn't have any effect.  Could you elaborate on what you mean when you say "it only adds another spread when the current one is 'full' according to its master spread."

The goal here is that I have a folder full of multi-page PDFs, and I want to place them on inDesign pages, with all the pages of a placed PDF together in a spread.  The PDFs have differing numbers of pages.  I'm able to do this manually within InDesign, but as you can imagine it's pretty tedious with a few dozen PDFs of 1-5 pages each.

P.S. the html DOM reference you put together is super helpful, thanks for that!

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 Expert ,
Aug 15, 2016 Aug 15, 2016

You could just apply the number of necessary pages to a document by setting one value.

var numberOfPagesInPDF = 123;

app.documents[0].documentPreferences.pagesPerDocument = numberOfPagesInPDF;

Regards,
Uwe

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
Explorer ,
Aug 15, 2016 Aug 15, 2016

Hello Laubender,

       To be clear, I'm not having trouble adding pages to the InDesign document.  I'm having trouble controlling whether the pages are added to the existing spread, or if a new spread is automatically created.  I would like to have all of the placed PDF pages together on a spread.  I'm able to do this manually.

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
Community Expert ,
Aug 15, 2016 Aug 15, 2016

So you have to add two ingredients to the mix:

document.documentPreferences.preserveLayoutWhenShuffling

document.documentPreferences.allowPageShuffle

spread.allowPageShuffle

Adobe InDesign CS6 (8.0) Object Model JS: DocumentPreference

jongware.mit.edu/idcs6js/pc_Spread.html

Regards,
Uwe

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
Explorer ,
Aug 16, 2016 Aug 16, 2016

Aha!   Thank you, that was the missing piece I wasn't understanding-- I had "Allow Document Pages to Shuffle" and "Allow Selected Spread to Shuffle" unchecked in the app, and it seems that new spreads that are added have the "Allow Selected Spread to Shuffle" on by default.  At least I think that was what was happening, those options are a little confusing to me.

For the benefit of anyone else facing this issue, the code that worked for me was:

      myDoc.documentPreferences.preserveLayoutWhenShuffling = true;

      myDoc.documentPreferences.allowPageShuffle = false;   

      mySpread.allowPageShuffle = false;

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 Expert ,
Aug 16, 2016 Aug 16, 2016
LATEST

That's why I pointed you to the fact, that allowPageShuffle is a property of the documentPreferences and a particular spread as well.

I'm glad, it's working for you now.

Note: Often it helps to see what the condition an object is in (your document, your added spread) if you try the task within the UI of InDesign and write out the steps you did as tasks that should be worked on for your script. You could have remembered then, that you probably changed the allowPageShuffle value for a particular spread before adding pages to that spread.

Regards,
Uwe

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