Skip to main content
Participating Frequently
January 30, 2023
Question

[JS] Remove Start section from selected pages in page panel

  • January 30, 2023
  • 1 reply
  • 313 views

I have a document that has every page set as "start section" on every page causing numbering issues if any pages are added/removed. I am trying to write a JS to remove Start section from all pages seclected in pages panel since the program will only change the page selected rather than multiples and I have several books with this issue. 

what I have so far with my base level knowledge of coding but it is breaking from the start so I must be doing something wrong.

var pages = app.selection[0].pages;

for (var i = 0; i < pages.length; i++) {

var page = pages[i];

var section = page.parent.sections.itemByName("start"); if (section != null) {

section.remove();

}

page.numberingContinues = true;

}

This topic has been closed for replies.

1 reply

Community Expert
January 30, 2023

You say: "…document that has every page set as "start section" on every page…"

And also: " I am trying to write a JS to remove Start section from all pages seclected in pages panel…"

 

Hi @BryceRobertsGD ,

why do you think that you need to select pages to remove sections of a document?

Object section is directly part of the document. So if you need to remove all sections of a document you could simply remove them all. With the exception of the first section that no-one can remove. The one on the first page of a document.

 

The ExtendScript code for this would be:

app.documents[0].sections.itemByRange( 1,-1 ).remove();

 

But first we have to be sure that the document has more than one section, so we would write:

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

 

Is this what you are after?

 

FWIW: Do not assume that if there are sections that restart page numbering that these sections automatically go by the name "start". Also do not assume that a selection of pages in the Page panel is a valid selection of pages. It is not. If you simply select some pages in the Page panel and nothing is selected on a given page, app.selection.length returns 0. To make a selection of pages you first need the Page tool activated and then a selection of pages in the Page panel.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Participating Frequently
January 30, 2023

That seems to have worked thank you so much!