[Solved] How to enumberate documents?

Creating a macro - Writing a Script - Using the API

[Solved] How to enumberate documents?

Postby grnhorn » Sun Aug 24, 2008 3:22 pm

How do I check for all open soffice documents? I found out that if I use ThisComponent.Close(True) or ThisComponent.Dispose it leaves soffice.exe and soffice.bin processes running. If I use StarDesktop.Terminate(), it will shut down all processes, but it will also close all open documents.

If I use File>Exit or the close 'X' on the caption bar the processes shut down (this has got to be a bug). I will be more then glad to skip the previous question if anyone has an answer to this issue.

Thanks...
Last edited by grnhorn on Sun Aug 24, 2008 6:59 pm, edited 1 time in total.
OOo 2.4.X on Ms Windows XP
grnhorn
 
Posts: 32
Joined: Sun Jul 13, 2008 2:07 pm

Re: How to enumberate documents?

Postby Villeroy » Sun Aug 24, 2008 4:47 pm

Code: Select all   Expand viewCollapse view
REM Basic
oEnum = StarDesktop.getComponents()

returns an enumeration of components (aka document models).
http://api.openoffice.org/docs/common/r ... Components
StarDesktop is a global helper variable in StarBasic similar to ThisComponent.
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: 26753
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

[Solved] How to enumberate documents?

Postby grnhorn » Sun Aug 24, 2008 6:59 pm

Thanks Villeroy, here is the final code I came up with. The only issue I found is that BasicIDE is included as a document.
Code: Select all   Expand viewCollapse view
Sub TerminateProcesses()
Dim sDocURL As String
Dim oDocs As Object
Dim oDoc As Object
Dim oComponents As Object

' Close document
    GlobalScope.BasicLibraries.LoadLibrary("Tools")
    sDocURL = ThisComponent.getURL()
    oDocs = StarDesktop.getComponents().createEnumeration()
    Do While oDocs.hasMoreElements()
      oDoc = oDocs.nextElement()
REM This line looks at the document you are working with and will terminate processes if nothing else is running;
REM otherwise it will close and leave the other running. 'Reverse "/" to get path without filename.
      If oDoc.URL <> DirectoryNameoutofPath(sDocURL, "\") Then ThisComponent.Close(True)
REM This line can be used to determine how many documents are open.
      'i = i + 1 'Counter
   Loop
REM This shuts down all running documents and terminates all running soffice processes
   StarDesktop.Terminate()   
End Sub
OOo 2.4.X on Ms Windows XP
grnhorn
 
Posts: 32
Joined: Sun Jul 13, 2008 2:07 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests