1 Reply Latest reply on Sep 12, 2011 4:21 AM by chucholap

    [CS4] "Progress bar" relative to the actual page number

    chucholap

      Hi!

      First of all thanks to the community. It's being really helpful with my start on inDesign scripting! 

       

      I'm trying to insert a kind of progress bar on each page showing the percentage of the pages you have already read. Something like this sketch:

      http://img89.imageshack.us/img89/5313/loadingbarindesign.png

      I think I can start with this script (by [Jongware]-GfBROo) that will set the size of the dark shape, but I don't know how to do it relative to the current page number... Any tip or link to some post I can adapt?

       

       

      //DESCRIPTION:Change all Swatch Objects size to a predefined value
       
      change_width = 10;
      change_height = 20;
      for (a=0; a<app.activeDocument.allPageItems.length; a++)
      {
       if (app.activeDocument.allPageItems[a].appliedObjectStyle.name == "swatch")
       {
        gb = app.activeDocument.allPageItems[a].geometricBounds;
       
        app.activeDocument.allPageItems[a].geometricBounds = [gb[0], gb[1], gb[0]+change_height, gb[1]+change_width];
       
       }
      }

       

       

      Thank you so much!

        • 1. Re: [CS4] "Progress bar" relative to the actual page number
          chucholap Level 1

          Problem solved!

          (thanks to andrewman from Domestika forums)

           

          Here is the script for my specifc requirements:

           

          /**
          * Progress bar
          * javascript (.jsx)
          */
          
          // Change according to the document
          width_bar = 20;
          style_name = "current_progress";
          
          
          num_pags = app.activeDocument.pages.length;
          increase = width_bar/num_pags;
          
          for( i=0; i < num_pags; i++ ) {
          pg = app.activeDocument.pages.item(i);
          for( j=0; j < pg.allPageItems.length; j++ ) {
          
          pgi = pg.allPageItems[j];
          if( pgi.appliedObjectStyle.name == style_name ) {
          dim = pgi.geometricBounds;
          
          progress = Math.round( (( dim[1] + increase ) + ( i * increase )) * 100 ) / 100;
          pgi.geometricBounds = [ dim[0], dim[1], dim[2], progress ];
          }
          }
          }
          
          alert('Done!');
          

           

          THINGS TO CHANGE: width of the bar (will be the length in the last page) and the style name you are going to use.

           

          Just need to create the bar on the master page, give it the style,  select all the pages and click "Override all Master Page Items". Run the script!

          If you add new pages, only need to override them and run the script again