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

is it possible to turn off start section on only selected pages using a script?

Engaged ,
Feb 02, 2021 Feb 02, 2021

Copy link to clipboard

Copied

I have a bunch of pages that are individually tagged as start section pages. I want to turn off the pages that are in a sequence. For example if I had pages 9-12,15,25,40-50, I would want to turn off start section for pages 10-12, and 41-50. That way those sections would still start at pg 9 and 40 but the rest would be automatic page numbering. The individual pages would remain untouched. I wondering the best way to do this.

 

1. Select the pages I want to turn off the start page option, and then run a script but I'm not sure if I can use selected pages as a input.

 

2. Use a script to detect sequential pages and process those. 

 

Any ideas on how to go about this?

 

 

 

TOPICS
Scripting

Views

538

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

correct answers 1 Correct answer

Community Expert , Feb 02, 2021 Feb 02, 2021

An alternate approach to find all pages selected in the Pages Panel would be:

 

[1] Switch to the Page Tool

[2] Select all pages where you want to remove sections in the Pages Panel

Now you can work with app.selection and iterate through the selected items; all selected items are actually pages.

That would you allow to remove the section entry:

 

var selectedPages = app.selection;

for( var n=0; n<selectedPages.length; n++ )
{
	var section = selectedPages[n].appliedSection;
	section.remove();
};
...

Votes

Translate

Translate
Community Expert ,
Feb 02, 2021 Feb 02, 2021

Copy link to clipboard

Copied

You can add new sections like this:

 

 

var doc = app.documents.item(0);

//which document page to start the section 
var ps = doc.pages[6];
//the section prefix
var pre = "Hello"
//add a new section
doc.sections.add({continueNumbering:false, pageStart:ps, pageNumberStart:1, sectionPrefix:pre, includeSectionPrefix:true})

 

Other section properties:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Section.html#d1e265407

 

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 Expert ,
Feb 02, 2021 Feb 02, 2021

Copy link to clipboard

Copied

Hi David,

unfortunately there still is no DOM command in scripting to detect pages that are selected in the Pages Panel.

But I solved this problem three years ago:

 

active page vs selected page
Correct answer by Laubender, Jan 15, 2017
https://community.adobe.com/t5/indesign/active-page-vs-selected-page/m-p/8776565#M35095

 

Regards,
Uwe Laubender

( ACP )

 

 

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 Expert ,
Feb 02, 2021 Feb 02, 2021

Copy link to clipboard

Copied

An alternate approach to find all pages selected in the Pages Panel would be:

 

[1] Switch to the Page Tool

[2] Select all pages where you want to remove sections in the Pages Panel

Now you can work with app.selection and iterate through the selected items; all selected items are actually pages.

That would you allow to remove the section entry:

 

var selectedPages = app.selection;

for( var n=0; n<selectedPages.length; n++ )
{
	var section = selectedPages[n].appliedSection;
	section.remove();
};

 

Warning: Make sure that you do not select the first page of your document in step 2.

The section there is the default one and cannot be removed.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

would it be possible to do this with a an arry instead of a selection, something like this but not this because it doesn't work?

var selectedPages = [10,11,12,41,42,43,44,45,46,47,48,49,50];

for( var n=0; n<selectedPages.length; n++ )
{
	var section = selectedPages[n].appliedSection;
	section.remove();
};

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 Expert ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

You should be able to add a line t Uwe’s script to invoke the Page Tool: 

 

app.menuActions.itemByName("Page Tool")

 

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 Expert ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Hi Rob,

no need for a menu action:

app.toolBoxTools.currentTool = UITools.PAGE_TOOL;

 

Regards,
Uwe Laubender

( ACP )

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 Expert ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

In principle, as an idea, your code will work.

You only have to access real pages in the active document.

And that can be done with the documentOffset value of a given page, an integer number where counting starts with the number 0 for the first page in the document, number 1 for the second page and so on.

See DOM documentation for this:

http://jongware.mit.edu/idcs6js/pc_Page.html#documentOffset

 

/*
	NOTE:
	doc.pages[ 10 ]
	is the eleventh page in your document!
	Regardless of its name.
*/
var documentOffsetNumbersArray = [10,11,12,41,42,43,44,45,46,47,48,49,50];
var doc = app.documents[0];

for( var n=0; n<documentOffsetNumbersArray.length; n++ )
{
	var currentDocOffsetNumber = documentOffsetNumbersArray[n] ;
	doc.pages[ currentDocOffsetNumber ].appliedSection.remove();
};

 

Alternatively, if you want to work with page names, using string values, that can be done as well.

But a page name could be "001" or "1" or "A" or "a" or "I" or any other string that is allowed for naming a page.

So if you have page names in your array instead of numbers it could work like that:

/*
	NOTE:
	doc.pages.itemByName("10")
	is the page in your document that has the name "10".
	It's NOT necessarily the tenth page in your document!
*/
var pageNamesArray = ["10","11","12","41","42","43","44","45","46","47","48","49","50"];
var doc = app.documents[0];

for( var n=0; n<pageNamesArray.length; n++ )
{
	var currentPageName = pageNamesArray[n] ;
	doc.pages.itemByName( currentPageName ).appliedSection.remove();
};

 

WARNING: Be aware that two different pages in the same document could share the same name!

So better work with documentOffset values.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

When I try to run this code I get the error message: Exception has occured. Error Code# 45: Object is invalid at the line below, do you know what might cause this?

 

doc.pages[ currentDocOffsetNumber ].appliedSection.remove();

 

Using this code from above.

var documentOffsetNumbersArray = [10,11,12,41,42,43,44,45,46,47,48,49,50];
var doc = app.documents[0];

for( var n=0; n<documentOffsetNumbersArray.length; n++ )
{
	var currentDocOffsetNumber = documentOffsetNumbersArray[n] ;
	doc.pages[ currentDocOffsetNumber ].appliedSection.remove();
};

 

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hi David,

could be that the page you'd like to address has no section entry.

The script does not test this. Remember that every number in your array reflect a position of a page in your document. And the numbering starts with 0 and not with 1. So the first entry in your array means the 11th page in the document and not a page named "10" or the 10th page in your document.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Thank you for your time Uwe,

This is definitely whats happening but I'm not sure how to get change it.

 

For example: if I set up the for loop and console log the results I get correct numbers but when it runs in practice it removes the sections from pages 3 and 4 then adds a page which is page 5 and removes that section(or doesn't have a section like you mentioned) and thats where is errors out.

   If I change it to n+1 or n-1 it doesn't work either. Where am I missunderstanding this?

 

//Page setup I start with is 1,2,3,4,13,27,30,31,32,33,34

var endPages = [2,3,4,31,32,33,34];//Pages I want to remove

for( var n=0; n < endPages.length; n++ )
{
    console.log(n);//result:0,1,2,3,4,5,6
	var currentDocOffsetNumber = endPages[n];
	doc.pages[ currentDocOffsetNumber ].appliedSection.remove();
    console.log(endPages[n]);//result:2,3,4,31,32,33,34
};

  

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Pages you want to remove?
That's a totally different thing to do.

Removing a section in my current code will remove the section entry only.

It will not remove pages.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Sorry I incorrectly noted that. It should be "Pages I want to remove the section on".

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Please share the InDesign document on Dropbox or a similar service and the index numbers of the pages ( the values in your array ) where you like to remove the section entry.

 

You could remove any contents in the document with:

app.documents[0].pageItems.everyItem().remove();

For testing something I only need the document with all its pages and the sections that are applied.

 

Thanks,
Uwe Laubender

( ACP )

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
Engaged ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

I would like to remove the sections from these pages:

 

[2,3,4,31,32,33,34]

 

https://www.dropbox.com/s/zaubsfsfwjgc920/sections.indd?dl=0

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

LATEST

Looked into your document.

Your index numbers in the array are the wrong ones.

 

I guess you want to address the second, the third, the fourth, the fifth page etc.pp. in your document.

This would be:

[1,2,3,4,5,6,7,8,9,10]

 

Regards,
Uwe Laubender

( ACP )

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