Skip to main content
Participant
February 11, 2014
Answered

Script to delete alternate layout

  • February 11, 2014
  • 3 replies
  • 1857 views

I am writing a script that puts ID documents into the correct folder and naming structure to be batch imported into a folio. The documents have two alternate layouts, the original "Print" layout and an "I" layout for ipad. I want the script to delete the "Print" layout pages before processing the document. This is effectively the first section of the document. If I try to target it as below, I receive an error that says cannot delete the doc's default section.

var allSections = myDoc.sections;

   var numSections = allSections.length;

  

   if (numSections > 1){

       allSections[0].remove();

       }

How do I correctly target this section, and what is the correct syntax for targeting it by it's altenate layout name, "Print"

Many thanks,

Tim

This topic has been closed for replies.
Correct answer Laubender

Bob Levine wrote:

BTW, when you get this working, I'd interested in hearing about it.

@Bob – I wondered why that would be interesting for you.

If you are scripter like Tim, one could use a function like this in a more complex script doing also other things.

If you just want to remove the pages of an alternate Layout, why not going to the Pages Panel and using the menu command for that?

Ok. Maybe I'm thinking in the wrong direction…


Maybe you mean NOT removing the pages, but removing the sections?

If one is moving pages from document A to document B, InDesign CS6 (and above) is always adding sections and alternate layout names to document B. This could be annoying.

To remove NOT the pages, but ALL the sections generated (except the first, that cannot be removed), use the following snippet:

if(app.documents[0].sections.length > 1){app.documents[0].sections.itemByRange(1,-1).remove()};

It basically means: remove the second section to the last section, if there is more than one section.

@Tim: Removing sections does not mean removing pages.

Uwe

3 replies

BobLevine
Community Expert
Community Expert
February 11, 2014

There's a dedicated scripting forum and a dedicated DPS forum. I would try

the scripting forum first.

BTW, when you get this working, I'd interested in hearing about it.

Community Expert
February 11, 2014

@Bob – Peter Spier already was so kind to move this thread to the scripting forum.

And: you could try my snippet to remove all pages of the first section of an InDesign file.
Don't know if it will work as expected in InDesign CS6 or CC in context of alternate layouts.

Will try testing it in CS6. Cannot test with InDesign CC…

Uwe

BobLevine
Community Expert
Community Expert
February 11, 2014

Thanks, Uwe.

I answer via email so it’s not always apparent if something’s been moved.

Community Expert
February 11, 2014

//EDIT: Ah. Peter already moved your question to the right forum while I was working on my answer. Thank you, Peter!

@Tim – this is the wrong forum to ask a scripting question.

There is a dedicated  InDesign Scripting Forum:

http://forums.adobe.com/community/indesign/indesign_scripting?view=discussions&start=0

But I can answer your question here:

1. Removing a section, does NOT remove its pages

2. If you remove a section (the first one cannot be removed!) all pages that belong to that section will now belong to a different section: the section that is ordered before the section you removed.

If you want to remove all pages of a section, you first have to find out the index of the first and the indexof the last page of that section and then remove pages in one go with the itemByRange() method.

So let's see. Test these lines of code individually to get a feeling for the values they return:

app.documents[0].sections.length;

app.documents[0].sections[0].length;

app.documents[0].sections[0].pageStart.documentOffset;

So if the first line returns a number higher than 1, we are ready to go.

The second one will give you the number of pages in that particular section.

The third one will give you the index of the first page that particular section will start (considering all pages in the document, beginning with index value 0 at the first page of your document).

So we have all ingredients for removing ALL pages of section 1 of the document:

if(app.documents[0].sections.length > 1){

    var pagesLengthOfSectionOne = app.documents[0].sections[0].length;

    var pagesOfSectionOneStartAtIndex = app.documents[0].sections[0].pageStart.documentOffset;

    app.documents[0].pages.itemByRange(pagesOfSectionOneStartAtIndex,pagesLengthOfSectionOne-1).remove();

    };

You'll find excellent DOM documentation here:

http://www.jongware.com/idjshelp.html

Uwe

Message was edited by: Laubender

Peter Spier
Community Expert
Community Expert
February 11, 2014

Moved to the Scripting forum...