Macro for number of the current Impress slide
Macro for number of the current Impress slide
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
where I can find further information on how to get that data?
please help
thanks
libreoffice 4.4 on debian 8
Re: macro, number of the current slide
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)
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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: macro, number of the current slide
The slide show controller has a method getCurrentSlideIndex.
I used some of this stuff, with a SlideShowListener, in a document posted in this thread.
I used some of this stuff, with a SlideShowListener, in a document posted in this thread.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: macro, number of the current slide
Interesting stuff for me who never runs any presentations. Testing this routine, I get an object not set error at the end of addListener.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.
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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: macro, number of the current slide
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:
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
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
libreoffice 4.4 on debian 8
Re: macro, number of the current slide
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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: macro, number of the current slide
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
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.
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
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
Windows XP
Re: Macro for number of the current Impress slide
I'm trying to run that code but on: Slide = oController.getCurrentSlideIndex
I get this error:
BASIC runtime error.
Object variable not set.
I get this error:
BASIC runtime error.
Object variable not set.
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
I haven't had the problem, but did you try adding the Wait statement to the addListener routine a Villeroy suggested?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.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
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
sorry but I'm new with macros
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
The eyechart example may be a little complex for starting out, but maybe if i point out a couple of things.maxt wrote:I get: "BASIC runtime error. Object variable not set." on the line: oPresentation.Start()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
sorry but I'm new with macros
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
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
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
now the presentation starts but I get:
BASIC runtime error.
Object variable not set.
on this line
oController.addSlideShowListener(oListener)
BASIC runtime error.
Object variable not set.
on this line
oController.addSlideShowListener(oListener)
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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
Windows XP
Re: Macro for number of the current Impress slide
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
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
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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.
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.
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
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
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:
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
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
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
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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
Windows XP
Re: Macro for number of the current Impress slide
also with MsgBox("hello") no messages appear
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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.
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
Windows XP
Re: Macro for number of the current Impress slide
and it doesn't appear..It will only appear after a slide change.
yes many thanksI could post a document that works for me, and you and others could test it.
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
Run the slide show by running the Main sub.
- Attachments
-
- HelloEyeChart.odp
- (16.22 KiB) Downloaded 302 times
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
on windows 7 and libreoffice 4.4 messagebox appears..
I think it's the linux version which is bugged..
I think it's the linux version which is bugged..
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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
Windows XP
Re: Macro for number of the current Impress slide
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
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
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
I'm not sure what this is saying. If it works, it should create a file - in the folder specified.maxt wrote:...but also writing to file works.. I don't see any made in the folder
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Macro for number of the current Impress slide
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
libreoffice 4.4 on debian 8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Macro for number of the current Impress slide
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.
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
Windows XP
Re: Macro for number of the current Impress slide
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
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 280 times
libreoffice 4.4 on debian 8