Feb 18, 2014

Impress Progress Bar

A few months ago I wanted to have a progress bar in an Impress presentation, but couldn't find a feature to generate it automatically. So I had to write a macro script... 

The script adds a bar with the percentage and width proportional to the position of the slide in the presentation.

Now I see there are other people wanting this functionality, so I'll publish it here:

 Sub InsertProgressBar  
 Dim oDoc As Object  
 oDoc = ThisComponent  
 ' Check if this is an Impress document  
 If thisComponent.supportsService("") Then  
      Dim oDrawPage As Object  
      Dim Point As New  
      Dim Size As New  
      Dim Factor As Double  
      Dim Percent As Integer  
      For n = 0 To oDoc.DrawPages.Count-1  
           oDrawPage = oDoc.DrawPages(n)  
           Factor = oDrawPage.Width / oDoc.DrawPages.Count  
           Size.Width = (n + 1) * Factor  
           Size.Height = oDrawPage.Height * 0.05  
           Point.x = 0  
           Point.y = oDrawPage.Height - Size.Height  
           m = oDrawPage.getCount-1  
           Do While (m >= 0)  
                mShape = oDrawPage.getByIndex(m)  
                If (InStr(mShape.Name, "Progress Bar Macro") <> 0) Then  
                End If  
                m = m-1  
           RectangleShape = oDoc.createInstance("")  
           RectangleShape.CharWeight =  
           RectangleShape.CharFontName = "Arial"  
           RectangleShape.Size = Size  
           RectangleShape.Position = Point  
           RectangleShape.Name = "Progress Bar Macro " + (n+1)  
           Percent = 100 * (n + 1) / oDoc.DrawPages.Count  
           ' RectangleShape.String = "" + oDrawPage.Number + " / " + Doc.DrawPages.Count + " (%" + Percent + ")"  
           RectangleShape.String = "%" + Percent  
      Next n  
 End If  
 End Sub  

You can copy the code above or download the .bas file BAS library from my github repo here.

Edit: Thanks to Leo Barichello we have now a dialog box and some customization options.

How to use: 

1st make a backup of your FINISHED presentation.

2nd execute the macro and a progress bar will be added to each slide, on top of whatever there is in it.

Use it freely but at you own risk, I wont be responsible for any loss or damage to your work or system.

Info on how to add/import a macro to your Open Office / Libre Office Suite is available on the net, so just use your favorite search engine to find how to do it.

TODO: maybe someone would like to add a dialog to choose different options for the progress bar...

NOTE: This screenshot is just a mockup

1 comment:

  1. Thank you, it was very useful!
    If I find some spare time, I may work in the dialog box.