[Solved] Presentation.Controller - "Null object"

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

[Solved] Presentation.Controller - "Null object"

Post by musa »

Hi all.
I try to run a macro (Impress):

Code: Select all

Sub Macro5()
Dim oDoc as Object
Dim oPresentation as Object
Dim oController as Object

oDoc = thisComponent
oPresentation = oDoc.Presentation
oController = oPresentation.Controller

If (Not GlobalScope.BasicLibraries.isLibraryLoaded("XrayTool")) Then GlobalScope.BasicLibraries.LoadLibrary("XrayTool")
  Xray oController

'oCurrentSlide = oController.CurrentSlide

End Sub
and I get a message "Null object".

How can I get an object "oController"?

Thanks!
Last edited by musa on Thu Nov 29, 2012 3:03 pm, edited 1 time in total.
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Presentation.Controller - "Null object"

Post by Charlie Young »

A presentation doesn't have a controller unless it is running.

Code: Select all

	oPresentation.Start()
	oController = oPresentation.Controller
This is a good thing, since the controller is only useful on a running presentation anyway.
Apache OpenOffice 4.1.1
Windows XP
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

Re: Presentation.Controller - "Null object"

Post by musa »

Code: Select all

oPresentation.Start()
Why?
But I've already started the presentation by pressing F5?
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Presentation.Controller - "Null object"

Post by Charlie Young »

musa wrote:

Code: Select all

oPresentation.Start()
Why?
But I've already started the presentation by pressing F5?
How are you running the macro then?
Apache OpenOffice 4.1.1
Windows XP
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

Re: Presentation.Controller - "Null object"

Post by musa »

Charlie Young wrote:
musa wrote:

Code: Select all

oPresentation.Start()
Why?
But I've already started the presentation by pressing F5?
How are you running the macro then?
The macro is executed when the user clicks on a certain slide.
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Presentation.Controller - "Null object"

Post by Charlie Young »

musa wrote:The macro is executed when the user clicks on a certain slide.

Assigned to some object through "Interaction?"

I don't know why it doesn't work then.

This works fine for me when assigned to some object on a slide, which is then clicked during the presentation:

Code: Select all

Sub CheckController()
	Dim oDoc As Object
	Dim oController As Object
	Dim oPresentation As Object
	
	oDoc = ThisComponent
	oPresentation = oDoc.Presentation
	oController = oPresentation.getController()
	XRayIt(oController)
End Sub 

sub XRayIt(It As Object)
	Globalscope.BasicLibraries.LoadLibrary( "XrayTool" )
			
	XRay(It)
End Sub

It doesn't make any difference whether I use the getController() method or just check the Controller property.
Apache OpenOffice 4.1.1
Windows XP
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

Re: Presentation.Controller - "Null object"

Post by musa »

Can you give me your full working example (example.odp)?
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

Re: Presentation.Controller - "Null object"

Post by musa »

This code works fine:

Code: Select all

Sub Main
oDPages = ThisComponent.DrawPages
oDP = oDPages.getByIndex(2)
oShape = oDP.getByIndex(2)

If oShape.String = "Click me" Then
	Click_me
End If

End Sub

Sub Click_me
       Dim oDoc As Object
       Dim oController As Object
       Dim oPresentation As Object
       
       oDoc = ThisComponent
       oPresentation = oDoc.Presentation
       oController = oPresentation.getController()
       oCurrentSlide=oController.getCurrentSlide()
       MsgBox "CurrentSllde.Name = " & oCurrentSlide.Name
End Sub
Thanks!
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Presentation.Controller - "Null object"

Post by Charlie Young »

musa wrote:Can you give me your full working example (example.odp)?
I went to bed right after my last post in this thread. I can work up an example if you still need it, but you have something going?
Apache OpenOffice 4.1.1
Windows XP
musa
Posts: 12
Joined: Wed Nov 28, 2012 8:50 pm

Re: [Solved]Presentation.Controller - "Null object"

Post by musa »

Thanks!
Don't need your example.
I've solved my problem.
Apache OOo 3.4.1 + LibreOffice 3.6.4
Windows XP + Ubuntu 12.04 + Puppy Linux
Post Reply