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

Exclude the Roman Numerals Number Page Section

Engaged ,
Jun 04, 2018 Jun 04, 2018

Copy link to clipboard

Copied

Hello!

In my Indesign document, normally my first pages are in Roman Numerals like you can see:

Screen Shot 2018-06-05 at 01.00.39.png

After I use the normal numbers like you can see:

Screen Shot 2018-06-05 at 01.06.57.png

Is there a script to know which number page start my normal number 1?

For example, if my document has the next pages:

I, II, III, IV, V, VI, VII, 1, 2, 3, 4, ...

this means my page 1 is in the number 8.

Here is the code but didn't works, because they find nothing in the number pages:

var doc = app.activeDocument;

// clear find change text preferences before search

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

// this is scripting equivalent of the 'Find What:' edit text field

app.findTextPreferences.findWhat = "1";

// search it in the active document

// you can also search it in almost everywhere: story, text frame, paragraph, line, word, etc

var finds = doc.findText();

if (finds.length > 0) { // something has been found

// for the 1st found item display the name of the page where the 1st text frame (there can be several threaded frames) containing it is located

alert("Found " + finds.length + " items, the first of them is on page " + finds[0].parentTextFrames[0].parentPage.name);

}

else { // found nothing

alert("Nothing has been found");

}

// clear find change text preferences after search

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

Maybe is helpful to know my number pages always have the style called Book Page Number  and is inside of my folder VARIOUS

I try also do this, but the script didn't find the number 1:

var myDoc = app.activeDocument,     

arrayRomanNumerals = ["1"],

I = arrayRomanNumerals.length,  i;     

app.findTextPreferences = null;   

for ( i = 0; i < I; i++) {        

    app.findTextPreferences.findWhat = arrayRomanNumerals;        

    myFound = myDoc.findText();     

    var J = myFound.length,  j;

    var styleBookPageNumber = myDoc.paragraphStyleGroups.itemByName("VARIOUS").paragraphStyles.itemByName("Book Page Number");

    for ( j = 0; j < J; j++) {   

        myFound.appliedCharacterStyle = myDoc.characterStyles[0];   

        if (myFound.appliedParagraphStyle == styleBookPageNumber) {   

            alert("Found!"); }

        else{break;}}}

Thanks so much.

TOPICS
Scripting

Views

737

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 , Jun 05, 2018 Jun 05, 2018

Hi Manuel,

a document can be parted in sections.

So I think, you are interested in object Section and several of its properties.

var sections = app.documents[0].sections.everyItem().getElements();

for( var n=0;n<sections.length;n++ )

{

var firstPageInSection = sections.pageStart;

var firstPageName = firstPageInSection.name;

var firstPageOfSectionPositionInDocument = firstPageInSection.documentOffset;

var pageNumberStyle = sections.pageNumberStyle;

$.writeln( n +"\t"+firstPageName );

$.writeln( n +"\t"+firs

...

Votes

Translate

Translate
People's Champ ,
Jun 04, 2018 Jun 04, 2018

Copy link to clipboard

Copied

A page object has a name property and a documentOffset property. myPage.documentOffset will always give you the number of the page in the document. Does that help?

Ariel

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 ,
Jun 05, 2018 Jun 05, 2018

Copy link to clipboard

Copied

Hi Ariel!

sorry I am beginner, I added this line but didn't work.:

            var RealNumberPage = myDoc.pages.item(styleBookPageNumber).documentOffset

            alert("The real first page, excluding the Roman Numerals is: " + RealNumberPage);

My full script:

var myDoc = app.activeDocument,    

arrayRomanNumerals = ["1"],

I = arrayRomanNumerals.length,  i;    

app.findTextPreferences = null;  

for ( i = 0; i < I; i++) {      

    app.findTextPreferences.findWhat = arrayRomanNumerals;      

    myFound = myDoc.findText();    

    var J = myFound.length,  j;

    var styleBookPageNumber = myDoc.paragraphStyleGroups.itemByName("VARIOUS").paragraphStyles.itemByName("Book Page Number");

    for ( j = 0; j < J; j++) {  

        myFound.appliedCharacterStyle = myDoc.characterStyles[0];  

        if (myFound.appliedParagraphStyle == styleBookPageNumber) {

            var RealNumberPage = myDoc.pages.item(styleBookPageNumber).documentOffset

            alert("The real first page, excluding the Roman Numerals is: " + RealNumberPage);

        }

        else{}}}

Thanks!

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
Guru ,
Jun 05, 2018 Jun 05, 2018

Copy link to clipboard

Copied

Replace

var RealNumberPage = myDoc.pages.item(styleBookPageNumber).documentOffset

with

parentPage = myFound.parentPage;

RealNumberPage = parentPage && parentPage.documentOffset

The parentPage could be null if the textFrame is of the page so we need to check there's a parent page and if so then we can get it's offset

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 ,
Jun 05, 2018 Jun 05, 2018

Copy link to clipboard

Copied

Hi Trevor,

I replace the line but still not working:

Please, here is my indesign file if you can check:

Download

Script:

var myDoc = app.activeDocument,      

arrayRomanNumerals = ["1"], 

I = arrayRomanNumerals.length,  i;      

app.findTextPreferences = null;    

for ( i = 0; i < I; i++) {        

    app.findTextPreferences.findWhat = arrayRomanNumerals;        

    myFound = myDoc.findText();      

    var J = myFound.length,  j; 

    var styleBookPageNumber = myDoc.paragraphStyleGroups.itemByName("VARIOUS").paragraphStyles.itemByName("Book Page Number"); 

    for ( j = 0; j < J; j++) {    

        myFound.appliedCharacterStyle = myDoc.characterStyles[0];    

        if (myFound.appliedParagraphStyle == styleBookPageNumber) {  

            parentPage = myFound.parentPage; 

            RealNumberPage = parentPage && parentPage.documentOffset;

            alert("The real first page, excluding the Roman Numerals is: " + RealNumberPage); 

        } 

        else{}}} 

Thanks 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
Community Expert ,
Jun 05, 2018 Jun 05, 2018

Copy link to clipboard

Copied

Hi Manuel,

a document can be parted in sections.

So I think, you are interested in object Section and several of its properties.

var sections = app.documents[0].sections.everyItem().getElements();

for( var n=0;n<sections.length;n++ )

{

var firstPageInSection = sections.pageStart;

var firstPageName = firstPageInSection.name;

var firstPageOfSectionPositionInDocument = firstPageInSection.documentOffset;

var pageNumberStyle = sections.pageNumberStyle;

$.writeln( n +"\t"+firstPageName );

$.writeln( n +"\t"+firstPageOfSectionPositionInDocument );

$.writeln( n +"\t"+pageNumberStyle.toString() );

}

See into documentation e.g.:

Adobe InDesign CS6 (8.0) Object Model JS: Section

Adobe InDesign CS6 (8.0) Object Model JS: PageNumberStyle

Regards,
Uwe

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 ,
Jun 05, 2018 Jun 05, 2018

Copy link to clipboard

Copied

LATEST

Hi Laubender!

amazing you help a lot!

var sections = app.documents[0].sections.everyItem().getElements(); 

 

for( var n=0;n<sections.length;n++ ) 

var firstPageInSection = sections.pageStart; 

var firstPageOfSectionPositionInDocument = firstPageInSection.documentOffset; 

//var firstPageName = firstPageInSection.name; 

//var pageNumberStyle = sections.pageNumberStyle; 

$.writeln( n +"\t"+firstPageOfSectionPositionInDocument );

//$.writeln( n +"\t"+firstPageName );   

//$.writeln( n +"\t"+pageNumberStyle.toString() );

if (firstPageOfSectionPositionInDocument != 0){

    alert (firstPageOfSectionPositionInDocument);

} else{};

Download the files

image-04.png

image-01.png

image-03.png

image-02.png

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