Page 1 of 2

Macro for number of the current Impress slide

Posted: Sat Mar 14, 2015 2:17 pm
by maxt
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

Re: macro, number of the current slide

Posted: Sat Mar 14, 2015 3:43 pm
by Villeroy
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)

Re: macro, number of the current slide

Posted: Sat Mar 14, 2015 4:14 pm
by Charlie Young
The slide show controller has a method getCurrentSlideIndex.

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

Re: macro, number of the current slide

Posted: Sun Mar 15, 2015 4:03 pm
by Villeroy
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

	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

Re: macro, number of the current slide

Posted: Sun Mar 15, 2015 5:41 pm
by maxt
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

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:

Re: macro, number of the current slide

Posted: Sun Mar 15, 2015 5:50 pm
by Villeroy
Hit F1 and look up the Open method in the Basic help.

Re: macro, number of the current slide

Posted: Sun Mar 15, 2015 6:12 pm
by Charlie Young
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

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.

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 12:52 am
by maxt
I'm trying to run that code but on: Slide = oController.getCurrentSlideIndex

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

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 1:03 am
by Charlie Young
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?

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 2:34 am
by maxt

Code: Select all

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

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 1:15 pm
by Charlie Young
maxt wrote:

Code: Select all

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

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

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

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 2:02 pm
by maxt
now the presentation starts but I get:
BASIC runtime error.
Object variable not set.

on this line
oController.addSlideShowListener(oListener)

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 3:56 pm
by Charlie Young
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.

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 6:49 pm
by maxt
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

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



Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 7:19 pm
by Charlie Young
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

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.

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 8:06 pm
by maxt
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

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




Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 8:18 pm
by Charlie Young
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

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

Re: Macro for number of the current Impress slide

Posted: Mon Mar 16, 2015 8:56 pm
by maxt
here is the full code, and no messagebox appears:

Code: Select all

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

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 1:15 am
by Charlie Young
Apparently "print" won't write anything over a running slide show, but it looks like MsgBox("hello") will.

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 9:48 am
by maxt
also with MsgBox("hello") no messages appear

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 12:43 pm
by Charlie Young
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.

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 1:08 pm
by maxt
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

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 1:19 pm
by Charlie Young
Run the slide show by running the Main sub.

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 3:08 pm
by maxt
on windows 7 and libreoffice 4.4 messagebox appears..

I think it's the linux version which is bugged..

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 3:29 pm
by Charlie Young
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.

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 7:09 pm
by maxt
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

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 7:23 pm
by Charlie Young
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.

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 7:56 pm
by maxt
this is the full code for now, and no file .txt is made in the directory

Code: Select all

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


Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 8:10 pm
by Charlie Young
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! 

Re: Macro for number of the current Impress slide

Posted: Tue Mar 17, 2015 9:53 pm
by maxt
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