[Solved] Impress Macro Not Working After Opening Draw

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
neobis001
Posts: 3
Joined: Sun Jul 10, 2022 1:07 am

[Solved] Impress Macro Not Working After Opening Draw

Post by neobis001 »

I tried this Impress macro out from this thread post:

Code: Select all

Sub Main
oPres = ThisComponent.Presentation
oPres.isEndless = True
oPres.isFullScreen = False
oPres.Start() 
End Sub
It works if Impress is the only program open. But I found one day that if I open a Draw file, then open an Impress file with the macro, then try to run the macro, it doesn't work anymore. I get an error for the line "oPres = ThisComponent.Presentation" which says "BASIC runtime error. Property or method not found: Presentation".

I uploaded an unlisted video to YouTube showing this:
"OpenOffice Impress Macro Not Working After Opening Draw"
https://youtu.be/BmNwrVT-ks8
0:13 I show the OpenOffice version and Java version (OpenOffice 4.1.12, Java 1.8.0_333, Windows 10)
2:26 is when I show the macro working
3:12 is when I show the macro not working after I open a Draw document

I don't know why the error appears with Draw. When I open the Draw file after I open the Impress file and run the Impress macro, it works. But when I open it before I open the Impress file, the macro doesn't work. It's a useful macro, and I don't want to have to worry about when I open a Draw file to use the Impress macro, so any bug fixes or alternate macros would be appreciated.
Last edited by Hagar Delest on Mon Jul 11, 2022 7:55 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 4.1.12 (Windows 10)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Impress Macro Not Working After Opening Draw

Post by Zizi64 »

The actual value of the ThisComponent depends on the application and document where you launched the macro. One "ThisComponent" has a property named ".Presentation" and an another has not.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Impress Macro Not Working After Opening Draw

Post by JeJe »

One way would be test to see if the currently active component is the right type with supportsservice and if not use the StarDesktop.components enumeration to find the one that is.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Impress Macro Not Working After Opening Draw

Post by Sébastien C »

Hello everyone !

I did EXACTLY the same actions as described in the video with LibreOffice (Version 7.3.4.2), i.e. open the Impress file AFTER the Draw file, then launch the macro. On Linux and on M$-Win (10), with LibreOffice, I do NOT reproduce. Because I also wanted to know OpenOffice’s reactions for my own tests, I installed this latest suite (4.1.12) under M$-Win (10). And I reproduce this error. The problem therefore comes from OpenOffice, which can actually be circumvented by enumerating the open files to find the correct one on which to apply the macro.
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Impress Macro Not Working After Opening Draw

Post by FJCC »

I think that finding the correct document among the open ones will not solve this problem. I used MRI to inspect ThisComponent when a Draw document had not been opened first and also when a Draw document had been opened. The Properties and Methods are different despite the fact that ThisComponent does refer to the Impress document. There is indeed no Presentation property. Also, the method getPresentation is not available. Strangely, the interface XPresentationSupplier is available and the API documentation shows its only method is getPresentation.

I do not know enough about how these things work to suggest a workaround other than the obvious route of not opening a Draw document first. I may play with this more later today and I'll report if I find anything interesting or useful.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Impress Macro Not Working After Opening Draw

Post by JeJe »

from Pitonyak's OpenOffice.org Macros Explained

Code: Select all

Listing 219. Determine a document's type.
Function getDocType(Optional vDoc) As String
 On Error GoTo Oops
 If IsMissing(vDoc) Then vDoc = ThisComponent
 If vDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
 getDocType = "calc"
 ElseIf vDoc.SupportsService("com.sun.star.text.TextDocument") Then
 getDocType = "writer"
 ElseIf vDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
 getDocType = "draw"
 ElseIf vDoc.SupportsService(_
 "com.sun.star.presentation.PresentationDocuments") Then
 getDocType = "presentation"
 ElseIf vDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
 getDocType = "math"
 ElseIf vDoc.SupportsService("com.sun.star.sdb.OfficeDatabaseDocument") Then
 getDocType = "base"
 Else
 getDocType = "unknown"
 End If
Oops:
 If Err <> 0 Then getDocType = "unknown"


 On Error GoTo 0 'Turn off error handling AFTER checking for an error
End Function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: Impress Macro Not Working After Opening Draw

Post by cwolan »

Code: Select all


ElseIf vDoc.SupportsService(_
 "com.sun.star.presentation.PresentationDocuments") Then
 getDocType = "presentation"
 
That should be "com.sun.star.presentation.PresentationDocument"
service PresentationDocument
OpenOffice 1.1.5 – 4.1.15
LibreOffice 6.4.7 – 7.6.5
Windows 7,10,11 64-bit
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Impress Macro Not Working After Opening Draw

Post by JeJe »

SupportsService("com.sun.star.presentation.PresentationDocuments") doesn't seem to work for me but this does:

(Edit: thanks, you possibly just explained that)

Code: Select all

sub test
vdoc=getPresentationDocument()
mri vdoc
end sub
function getPresentationDocument() as object
dim en,vdoc
on error resume next
en=stardesktop.getcomponents.createenumeration
do while en.hasmoreelements
vdoc=en.nextelement
if vDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
getPresentationDocument = vdoc
exit do
end if
loop
hr:
end function

EDIT: Oops Drawing documents support .GenericDrawingDocument too so I messed the above up anyway. Amended
Last edited by JeJe on Mon Jul 11, 2022 12:19 am, edited 2 times in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
neobis001
Posts: 3
Joined: Sun Jul 10, 2022 1:07 am

Re: Impress Macro Not Working After Opening Draw

Post by neobis001 »

I don't know much about macros. I just copied/pasted the Impress one. But I think I get JeJe's code. Enumerate components until I find something that has the right service, and hopefully it'll have a Presentation property.

I tried JeJe's getPresentationDocument() function, but I still get the same error:
1. It works with just the Impress file.
2. It doesn't work if I open the Draw file before the Impress file.

I put a screenshot of the error below. I show with a commented line that I also tried searching for the "com.sun.star.presentation.PresentationDocument" service in the enumeration. I thought that could find the Impress file's component (which I guess would also have the Presentation property), but the same 2 things I listed above happen.
enumerate-error-small-bit-depth.png
enumerate-error-small-bit-depth.png (89.85 KiB) Viewed 1442 times
OpenOffice 4.1.12 (Windows 10)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Impress Macro Not Working After Opening Draw

Post by JeJe »

I see the bug. Another way is to enumerate the frames. The same problem - it does get the right component - the problem is properties like presentation aren't available when you've loaded a drawing first.

Code: Select all


sub test
vdoc=getPresentationDocument()
mri vdoc
end sub
function getPresentationDocument() as object
dim en,vdoc
en=stardesktop.getframes
for i = 0 to en.count - 1
if right( en.getbyindex(i).title,7) ="Impress" Then
getPresentationDocument = en(i).controller.model
exit for
end if
next
hr:
end function




Without the draw document MRI gives
(Name) (Value Type) (Value) (Info.) (Attr.) (Handle)
AllowMacroExecution boolean True Attr. Read_Only
ApplyFormDesignMode boolean False 7
Args [].beans.PropertyValue -Sequence- Pseud Read_Only
AutomaticControlFocus boolean False 6
AvailableServiceNames []string -Sequence- Pseud Read_Only
AvailableViewControllerNames []string -Sequence- Pseud Read_Only
BasicLibraries .script.XLibraryContainer -INTERFACE- Read_Only 8
BuildId string "" 10
CharLocale .lang.Locale -STRUCT- 1
Controllers .container.XEnumeration -INTERFACE- Pseud Read_Only
CurrentController .frame.XController -INTERFACE- Pseud
CurrentSelection .uno.XInterface -void- Pseud Read_Only
CustomPresentations .container.XNameContainer -INTERFACE- Pseud Read_Only
DialogLibraries .script.XLibraryContainer -INTERFACE- Read_Only 12
DocumentInfo .document.XDocumentInfo -INTERFACE- Pseud Read_Only
DocumentProperties .document.XDocumentProperties -INTERFACE- Pseud Read_Only
DocumentStorage .embed.XStorage -INTERFACE- Pseud Read_Only
DocumentSubStoragesNames []string -Sequence- Pseud Read_Only
DrawPages .drawing.XDrawPages -INTERFACE- Pseud Read_Only
Events .container.XNameReplace -INTERFACE- Pseud Read_Only
ForbiddenCharacters .i18n.XForbiddenCharacters -INTERFACE- Read_Only 5
HandoutMasterPage .drawing.XDrawPage -INTERFACE- Pseud Read_Only
HasValidSignatures boolean False Read_Only 11
Identifier string com.sun.star.pr... Pseud
ImplementationId []byte -SEQUENCE- Pseud Read_Only
ImplementationName string SdXImpressDocument Pseud Read_Only
LayerManager .container.XNameAccess -INTERFACE- Pseud Read_Only
LibraryContainer .container.XNameContainer -INTERFACE- Pseud Read_Only
Links .container.XNameAccess -INTERFACE- Pseud Read_Only
LocalName string "" Attr. Read_Only
Location string "" Pseud Read_Only
MapUnit short 0 Read_Only 4
MasterPages .drawing.XDrawPages -INTERFACE- Pseud Read_Only
Modified boolean Ignored
Namespace string vnd.sun.star.td... Attr. Read_Only
Parent .uno.XInterface -void- Pseud
Presentation .presentation.XPresentation -INTERFACE- Pseud Read_Only
Printer [].beans.PropertyValue Ignored
PropertySetInfo .beans.XPropertySetInfo -INTERFACE- Pseud Read_Only
RDFRepository .rdf.XRepository -INTERFACE- Pseud Read_Only
RuntimeUID string 1 Read_Only 9
ScriptContainer .document.XEmbeddedScripts -INTERFACE- Attr. Read_Only
ScriptProvider .script.provider.XScriptProvider -INTERFACE- Pseud Read_Only
StringValue string vnd.sun.star.td... Attr. Read_Only
StyleFamilies .container.XNameAccess -INTERFACE- Pseud Read_Only
SupportedServiceNames []string -Sequence- Pseud Read_Only
TabStop long 1250 2
Title string Untitled 1 Pseud
TransferDataFlavors [].datatransfer.DataFlavor -Sequence- Pseud Read_Only
Types []type -Sequence- Pseud Read_Only
UIConfigurationManager .ui.XUIConfigurationManager Ignored Read_Only
URL string "" Pseud Read_Only
UndoManager .document.XUndoManager -INTERFACE- Pseud Read_Only
UntitledPrefix string : Pseud Read_Only
ViewData .container.XIndexAccess -INTERFACE- Pseud
VisibleArea .awt.Rectangle -STRUCT- 3
With it loaded first MRI gives
(Name) (Value Type) (Value) (Info.) (Attr.) (Handle)
AllowMacroExecution boolean True Attr. Read_Only
ApplyFormDesignMode boolean False 7
Args [].beans.PropertyValue -Sequence- Pseud Read_Only
AutomaticControlFocus boolean False 6
AvailableServiceNames []string -Sequence- Pseud Read_Only
AvailableViewControllerNames []string -Sequence- Pseud Read_Only
BasicLibraries .script.XLibraryContainer -INTERFACE- Read_Only 8
BuildId string "" 10
CharLocale .lang.Locale -STRUCT- 1
Controllers .container.XEnumeration -INTERFACE- Pseud Read_Only
CurrentController .frame.XController -INTERFACE- Pseud
CurrentSelection .uno.XInterface -void- Pseud Read_Only
DialogLibraries .script.XLibraryContainer -INTERFACE- Read_Only 12
DocumentInfo .document.XDocumentInfo -INTERFACE- Pseud Read_Only
DocumentProperties .document.XDocumentProperties -INTERFACE- Pseud Read_Only
DocumentStorage .embed.XStorage -INTERFACE- Pseud Read_Only
DocumentSubStoragesNames []string -Sequence- Pseud Read_Only
DrawPages .drawing.XDrawPages -INTERFACE- Pseud Read_Only
Events .container.XNameReplace -INTERFACE- Pseud Read_Only
ForbiddenCharacters .i18n.XForbiddenCharacters -INTERFACE- Read_Only 5
HasValidSignatures boolean False Read_Only 11
Identifier string com.sun.star.pr... Pseud
ImplementationId []byte -SEQUENCE- Pseud Read_Only
ImplementationName string SdXImpressDocument Pseud Read_Only
LayerManager .container.XNameAccess -INTERFACE- Pseud Read_Only
LibraryContainer .container.XNameContainer -INTERFACE- Pseud Read_Only
Links .container.XNameAccess -INTERFACE- Pseud Read_Only
LocalName string "" Attr. Read_Only
Location string "" Pseud Read_Only
MapUnit short 0 Read_Only 4
MasterPages .drawing.XDrawPages -INTERFACE- Pseud Read_Only
Modified boolean Ignored
Namespace string vnd.sun.star.td... Attr. Read_Only
Parent .uno.XInterface -void- Pseud
Printer [].beans.PropertyValue Ignored
PropertySetInfo .beans.XPropertySetInfo -INTERFACE- Pseud Read_Only
RDFRepository .rdf.XRepository -INTERFACE- Pseud Read_Only
RuntimeUID string 2 Read_Only 9
ScriptContainer .document.XEmbeddedScripts -INTERFACE- Attr. Read_Only
ScriptProvider .script.provider.XScriptProvider -INTERFACE- Pseud Read_Only
StringValue string vnd.sun.star.td... Attr. Read_Only
StyleFamilies .container.XNameAccess -INTERFACE- Pseud Read_Only
SupportedServiceNames []string -Sequence- Pseud Read_Only
TabStop long 1250 2
Title string Untitled 2 Pseud
TransferDataFlavors [].datatransfer.DataFlavor -Sequence- Pseud Read_Only
Types []type -Sequence- Pseud Read_Only
UIConfigurationManager .ui.XUIConfigurationManager Ignored Read_Only
URL string "" Pseud Read_Only
UndoManager .document.XUndoManager -INTERFACE- Pseud Read_Only
UntitledPrefix string : Pseud Read_Only
ViewData .container.XIndexAccess -INTERFACE- Pseud
VisibleArea .awt.Rectangle -STRUCT- 3

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Impress Macro Not Working After Opening Draw

Post by JeJe »

Switch to LibreOffice is often offered as a solution at these moments - though they've introduced some of their own extra bugs with that fork.

Can you manage without the omitted properties?

Edit: Drawing documents support .GenericDrawingDocument too so I messed the first code up anyway - sorry. Amended
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
neobis001
Posts: 3
Joined: Sun Jul 10, 2022 1:07 am

Re: Impress Macro Not Working After Opening Draw

Post by neobis001 »

Yeah, I tried this on LibreOffice 7.3.4.2 like Sebastien did, and it worked fine. I can use LibreOffice from now on.

I don't have to use OpenOffice. I was just surprised because this was my first time trying macros and I found something so strange with it even though it was only 4 lines. I thought I messed something up, like maybe I set up Java wrong or I did something wrong while creating a new macro. So I wanted to ask about it here.
OpenOffice 4.1.12 (Windows 10)
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: [Solved] Impress Macro Not Working After Opening Draw

Post by cwolan »

I filed a Bugzilla issue: 128527
OpenOffice 1.1.5 – 4.1.15
LibreOffice 6.4.7 – 7.6.5
Windows 7,10,11 64-bit
Post Reply