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

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

Community Beginner ,
Jan 30, 2023 Jan 30, 2023

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;

}

TOPICS
Scripting

Views

173

Translate

Translate

Report

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 ,
Jan 30, 2023 Jan 30, 2023

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 )

Votes

Translate

Translate

Report

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 ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

LATEST

That seems to have worked thank you so much!

Votes

Translate

Translate

Report

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