Macro for number of the current Impress slide

Creating a macro - Writing a Script - Using the API

Macro for number of the current Impress slide

Postby maxt » Sat Mar 14, 2015 2:17 pm

I need to put in a variable (inside a macro) the number of the current slide shown, and if possible also the name of the current slide

where I can find further information on how to get that data?
please help

thanks
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: macro, number of the current slide

Postby Villeroy » Sat Mar 14, 2015 3:43 pm

Add some invisible element to keep that number.
Write a macro to refresh the index when needed for x = 0 to slides.count : myHiddenIndexBox.setString(x)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27392
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: macro, number of the current slide

Postby Charlie Young » Sat Mar 14, 2015 4:14 pm

The slide show controller has a method getCurrentSlideIndex.

I used some of this stuff, with a SlideShowListener, in a document posted in this thread.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: macro, number of the current slide

Postby Villeroy » Sun Mar 15, 2015 4:03 pm

Charlie Young wrote:The slide show controller has a method getCurrentSlideIndex.

I used some of this stuff, with a SlideShowListener, in a document posted in this thread.

Interesting stuff for me who never runs any presentations. Testing this routine, I get an object not set error at the end of addListener.

This quick fix works for me:
Code: Select all   Expand viewCollapse view
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27392
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: macro, number of the current slide

Postby maxt » Sun Mar 15, 2015 5:41 pm

please help me writing this macro... I'm not expert with macro java/api etc..
In the past I wrote some little programs in C...

this is the actual macro I was trying to write:

Code: Select all   Expand viewCollapse view
Sub Main

Dim sFileName As String
  Dim n As Integer
  Dim t As String, d As Double, s As String
  sFileName = "/home/user/currentslide.txt"
  n = FreeFile()
 
 
Open sFileName For Output Access Read Write As #n

Print #n, "A"
   
close #n
End Sub



this create a file .txt and put in "A" letter
instead of this, I need to write a variable which contains the number of the current slide..

I want to write in that file the current slide number.. so I need to update that file every time a new slide is shown

please help me finish to write this macro

thanks :bravo:
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: macro, number of the current slide

Postby Villeroy » Sun Mar 15, 2015 5:50 pm

Hit F1 and look up the Open method in the Basic help.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27392
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: macro, number of the current slide

Postby Charlie Young » Sun Mar 15, 2015 6:12 pm

I'm not sure if it's in the posted version since I played with that EyeChart stuff for awhile after I posted that EyeChartx, but my current version has

Code: Select all   Expand viewCollapse view
Sub EV_slideTransitionStarted(oEv)
   Dim Slide As Integer
   Slide = oController.getCurrentSlideIndex
   Open "C:\Documents and Settings\Charlie\My Documents\LastSlide.txt" For Output As #1
   Print #1,Slide
   Close #1
   PlotEyeChart(Slide, Charts(Slide))
End Sub


But obviously that will cause problems for anyone not running Windows or not named Charlie

I don't remember when or why I added that.

I think I did wind up writing a c++ program to do the eye chart stuff (through automation). I'll look around for that.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 12:52 am

I'm trying to run that code but on: Slide = oController.getCurrentSlideIndex

I get this error:
BASIC runtime error.
Object variable not set.
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Mon Mar 16, 2015 1:03 am

maxt wrote:I'm trying to run that code but on: Slide = oController.getCurrentSlideIndex

I get this error:
BASIC runtime error.
Object variable not set.


I haven't had the problem, but did you try adding the Wait statement to the addListener routine a Villeroy suggested?
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 2:34 am

Code: Select all   Expand viewCollapse view
Sub main
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
End Sub


I get: "BASIC runtime error. Object variable not set." on the line: oPresentation.Start()

sorry but I'm new with macros
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Mon Mar 16, 2015 1:15 pm

maxt wrote:
Code: Select all   Expand viewCollapse view
Sub main
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
End Sub


I get: "BASIC runtime error. Object variable not set." on the line: oPresentation.Start()

sorry but I'm new with macros


The eyechart example may be a little complex for starting out, but maybe if i point out a couple of things.

First off, I always start out with Option Explicit at the top of the module, which means the variables have to be explicitly declared before they are used. This example using the SlideShowListener requires several variables to be declared "Global" at the top of the program, which means that if the name is not redeclared within a subroutine, a reference to the name in any routine refers to the same variable. In the eyechart example, we have

Code: Select all   Expand viewCollapse view
Global oDoc As Object
Global oPresentation As Object
Global oController As Object   
Global oListener As Object
Global Charts(2) As EyeChart


We can ignore the Charts variable for now, which is very specific to the particular example, but the others are all important and must be defined before use, or you will get errors like "Object variable not set."

Code: Select all   Expand viewCollapse view
Sub addListener
   oDoc = ThisComponent
   oDoc.Presentation.CustomShow = ""
   oDoc.Presentation.IsShowAll = True
   oPresentation = oDoc.Presentation
   oPresentation.IsEndless = False
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   oController.addSlideShowListener(oListener)
   
end sub
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 2:02 pm

now the presentation starts but I get:
BASIC runtime error.
Object variable not set.

on this line
oController.addSlideShowListener(oListener)
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Mon Mar 16, 2015 3:56 pm

Are you using the Wait statement? Note that Villeroy's Wait 100 only waits for a tenth of a second, so you might need a longer one.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 6:49 pm

ok, with wait 100
no errors are reported

next question is: where to write my macro that write to a txt file? in which sub? and how to connect that sub to each slide?

this is the actual code
Code: Select all   Expand viewCollapse view
Global oDoc As Object
Global oPresentation As Object
Global oController As Object   
Global oListener As Object



Sub addListener
   oDoc = ThisComponent
   oDoc.Presentation.CustomShow = ""
   oDoc.Presentation.IsShowAll = True
   oPresentation = oDoc.Presentation
   oPresentation.IsEndless = True
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
   
end sub




Sub EV_slideTransitionStarted(oEv)
   Dim Slide As Integer
   Slide = oController.getCurrentSlideIndex
   Open "/home/luivin/Desktop/macro/LastSlide.txt" For Output As #1
   Print #1,Slide
   Close #1
  ' PlotEyeChart(Slide, Charts(Slide))
End Sub


libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Mon Mar 16, 2015 7:19 pm

It would seem to make perfect sense, if you just want to write the slide number to a file, just do so whenever you get the slide number, which I get in the slideTransitionStarted routine of the listener. Again, the path is tailored to my system.


Code: Select all   Expand viewCollapse view
Sub EV_slideTransitionStarted(oEv)
   Dim Slide As Integer
   Slide = oController.getCurrentSlideIndex
   Open "C:\Documents and Settings\Charlie\My Documents\LastSlide.txt" For Output As #1
   Print #1,Slide
   Close #1
   PlotEyeChart(Slide, Charts(Slide))
End Sub


Note that this runs the PlotEyeChart for every slide, but each slide's layout is specified by an element of the Charts array. Whether something like that would work in your case depends on the details of your project, but you could also construct a Select...Case to specify a different macro for each slide.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 8:06 pm

for testing I've written:

Sub EV_slideTransitionStarted(oEv)
print "hello"
End Sub

but no message appears.. I don't understand why
shouldn't appear the message box on each slide shown??


here is the complete source:

Code: Select all   Expand viewCollapse view
Global oDoc As Object
Global oPresentation As Object
Global oController As Object   
Global oListener As Object



Sub addListener
   oDoc = ThisComponent
   oDoc.Presentation.CustomShow = ""
   oDoc.Presentation.IsShowAll = True
   oPresentation = oDoc.Presentation
   oPresentation.IsEndless = True
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
   
end sub




Sub EV_slideTransitionStarted(oEv)
print "hello"
End Sub



libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Mon Mar 16, 2015 8:18 pm

I'm not sure if this is the whole problem, but when implementing a listener it is necessary to include all its methods even if some aren't actually used
Code: Select all   Expand viewCollapse view
Sub EV_paused(oEv)
End Sub

Sub EV_resumed(oEv)
End Sub

Sub EV_slideTransitionStarted(oEv)
   Dim Slide As Integer
   Slide = oController.getCurrentSlideIndex
   Open "C:\Documents and Settings\Charlie\My Documents\LastSlide.txt" For Output As #1
   Print #1,Slide
   Close #1
   PlotEyeChart(Slide, Charts(Slide))
End Sub

Sub EV_slideTransitionEnded(oEv)
   
End Sub

Sub EV_slideAnimationEnded(oEv)
End Sub

Sub EV_slideEnded(oEv)
   
End Sub

Sub EV_hyperLinkClicked(oEv)
End Sub

Sub EV_disposing(oEv)
End Sub
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Mon Mar 16, 2015 8:56 pm

here is the full code, and no messagebox appears:

Code: Select all   Expand viewCollapse view
Global oDoc As Object
Global oPresentation As Object
Global oController As Object   
Global oListener As Object



Sub addListener
   oDoc = ThisComponent
   oDoc.Presentation.CustomShow = ""
   oDoc.Presentation.IsShowAll = True
   oPresentation = oDoc.Presentation
   oPresentation.IsEndless = True
   oListener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
   oPresentation.Start()
   oController = oPresentation.Controller
   wait 100 ' <--- oPresentation.Controller needs some time
   oController.addSlideShowListener(oListener)
   
end sub






Sub EV_paused(oEv)
End Sub

Sub EV_resumed(oEv)
End Sub


Sub EV_slideTransitionStarted(oEv)
print "hello"
End Sub

Sub EV_slideTransitionEnded(oEv)
   
End Sub

Sub EV_slideAnimationEnded(oEv)
End Sub

Sub EV_slideEnded(oEv)
   
End Sub

Sub EV_hyperLinkClicked(oEv)
End Sub

Sub EV_disposing(oEv)
End Sub
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 1:15 am

Apparently "print" won't write anything over a running slide show, but it looks like MsgBox("hello") will.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 9:48 am

also with MsgBox("hello") no messages appear
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 12:43 pm

It will only appear after a slide change.

If that isn't it, I've got to wonder if this is a problem with LibreOffice vs. OpenOffice. I could post a document that works for me, and you and others could test it.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 1:08 pm

It will only appear after a slide change.

and it doesn't appear..

I could post a document that works for me, and you and others could test it.


yes many thanks
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 1:19 pm

Run the slide show by running the Main sub.
Attachments
HelloEyeChart.odp
(16.22 KiB) Downloaded 86 times
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 3:08 pm

on windows 7 and libreoffice 4.4 messagebox appears..

I think it's the linux version which is bugged..
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 3:29 pm

Well, wouldn't this be a rather trivial bug? I was under the impression that the message box was just to check if the listener was working, which could also be done by other means, say by writing a file, then checking for the file and its contents. Maybe I'm mistaken, but it would seem undesirable to pop up a message box in the middle of a presentation usually.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 7:09 pm

in linux debian 6 + openoffice 4.1.1 no messages are shown

it seems that in linux not only msgbox are shown, but also writing to file works.. I don't see any made in the folder
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 7:23 pm

maxt wrote:...but also writing to file works.. I don't see any made in the folder


I'm not sure what this is saying. If it works, it should create a file - in the folder specified.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 7:56 pm

this is the full code for now, and no file .txt is made in the directory

Code: Select all   Expand viewCollapse view
Global oDoc As Object
Global oPresentation As Object
Global oController As Object   
Global oListener As Object


Sub main
Doc = ThisComponent
Presentation = Doc.Presentation
Listener = createUnoListener("EV_","com.sun.star.presentation.XSlideShowListener")
Presentation.Start()
Controller = Presentation.Controller
wait 100 ' <--- oPresentation.Controller needs some time
Controller.addSlideShowListener(Listener)
   
end sub



Sub EV_paused(oEv)
End Sub

Sub EV_resumed(oEv)
End Sub

Sub EV_slideTransitionStarted(oEv)
'Print "Transition Started"
'MsgBox("hello")


   Dim n As Integer
   Dim Slide As Integer
   
   Slide = oController.getCurrentSlideIndex
   
     sFileName = "/home/luivin/Desktop/macro/LastSlide.txt"
     n = FreeFile()
   Open sFileName For Output Access Read Write As #n
   Print #n,Slide
close #n


End Sub

Sub EV_slideTransitionEnded(oEv)
End Sub

Sub EV_slideAnimationEnded(oEv)
End Sub

Sub EV_slideEnded(oEv)
End Sub

Sub EV_hyperLinkClicked(oEv)
End Sub

Sub EV_disposing(oEv)
End Sub

libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Re: Macro for number of the current Impress slide

Postby Charlie Young » Tue Mar 17, 2015 8:10 pm

Have you looked after changing slides? I hadn't thought of it before, but if you want to write slide number 0 to the file initially, you'll need to do it in addListener, you could do it right after addSlideShowListener.

Maybe you could supply a copy of your document, with personal and confidential stuff removed.

 Edit: Wait a minute. In main, your using variable Controller, it should be oController! 
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro for number of the current Impress slide

Postby maxt » Tue Mar 17, 2015 9:53 pm

I changed to oControll but nothing change

I've also set breakpoints on the sub which write to file and no break happens, so it's as if the sub is never executed

this is the test file
Attachments
macro.odp
(11.94 KiB) Downloaded 81 times
libreoffice 4.4 on debian 8
maxt
 
Posts: 19
Joined: Tue Feb 24, 2015 11:18 am

Next

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests