6 Replies Latest reply on Jun 5, 2018 11:20 AM by manuelb27477138

    Exclude the Roman Numerals Number Page Section

    manuelb27477138 Level 1

      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[i];         
          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[j].appliedCharacterStyle = myDoc.characterStyles[0];    
              if (myFound[j].appliedParagraphStyle == styleBookPageNumber) {    
                  alert("Found!"); } 
              else{break;}}}
      

       

       

       

      Thanks so much.

        • 1. Re: Exclude the Roman Numerals Number Page Section
          TᴀW Adobe Community Professional & MVP

          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

          • 2. Re: Exclude the Roman Numerals Number Page Section
            manuelb27477138 Level 1

            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[i];       
                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[j].appliedCharacterStyle = myDoc.characterStyles[0];   
                    if (myFound[j].appliedParagraphStyle == styleBookPageNumber) { 
                        var RealNumberPage = myDoc.pages.item(styleBookPageNumber).documentOffset
                        alert("The real first page, excluding the Roman Numerals is: " + RealNumberPage);
                    }
                    else{}}}
            

             

             

            Thanks!

            • 3. Re: Exclude the Roman Numerals Number Page Section
              Trevorׅ Adobe Community Professional

              Replace

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

               

              with

              parentPage = myFound[j].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

              • 4. Re: Exclude the Roman Numerals Number Page Section
                manuelb27477138 Level 1

                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[i];         
                    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[j].appliedCharacterStyle = myDoc.characterStyles[0];     
                        if (myFound[j].appliedParagraphStyle == styleBookPageNumber) {   
                            parentPage = myFound[j].parentPage;  
                            RealNumberPage = parentPage && parentPage.documentOffset; 
                            alert("The real first page, excluding the Roman Numerals is: " + RealNumberPage);  
                        }  
                        else{}}}  
                

                 

                 

                Thanks so much!

                • 5. Re: Exclude the Roman Numerals Number Page Section
                  Laubender Adobe Community Professional & MVP

                  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[n].pageStart;
                  var firstPageName = firstPageInSection.name;
                  var firstPageOfSectionPositionInDocument = firstPageInSection.documentOffset;
                  var pageNumberStyle = sections[n].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

                  • 6. Re: Exclude the Roman Numerals Number Page Section
                    manuelb27477138 Level 1

                    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[n].pageStart;  
                    var firstPageOfSectionPositionInDocument = firstPageInSection.documentOffset;  
                    //var firstPageName = firstPageInSection.name;  
                    
                    
                    //var pageNumberStyle = sections[n].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