Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
That seems to have worked thank you so much!