[Solved] Umbrella macro to call two other macros not working

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Davidcannon65
Posts: 15
Joined: Sat Oct 02, 2021 12:34 pm

[Solved] Umbrella macro to call two other macros not working

Post by Davidcannon65 »

I have two macros, both of which work perfectly by themselves. One has a list of boys' names and the other a list of girls' names, for a local school. The macros find the names in a text and copies them to the clipboard. So far, so good.

Occasionally I need to use both macros in the same document. That's not a problem, but I tried to automate the process by making an “umbrella” macro to “call” both of these macros. It doesn't work. This is what I have so far. N.B The real macros have thousands of names, but I have deleted most of them here and have left just three in each macro, so that I don't have to waste space with them here. The "Umbrella macro" is at the end.

Code: Select all

sub FindBoysNames

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")


rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"

args1(10).Value= "Alan, Peter, Michael”
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1024
args1(17).Name = "SearchItem.Command"
args1(17).Value = 1
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())


end sub

Code: Select all

sub FindGirlsNames

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")


rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"

args1(10).Value= "Caroline, Jenny, Susan”
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1024
args1(17).Name = "SearchItem.Command"
args1(17).Value = 1
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())


end sub
And here's the “umbrella macro” — which doesn't work properly. Instead of calling both macros and copying the content to two clips (I've got a clipboard that holds multiple clips), it only copies one of them. What am I doing wrong?

Code: Select all

sub AllNames

Call FindBoysNames
Call FindGirlsNames

end sub
Last edited by robleyd on Mon Oct 11, 2021 1:02 pm, edited 2 times in total.
Reason: Add CODE tags for readability; tag [Solved]
OpenOffice 4.1.10 on Windows 8.1
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: "Umbrella macro" to call two other macros not working

Post by Zizi64 »

(I've got a clipboard that holds multiple clips)
Maybe the AOO uses the System clipboard. The Clipboard of the System can store one copied item only.

(Note: there are more incompatibility problems with the third party clipboard manager softwares.)
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: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: "Umbrella macro" to call two other macros not working

Post by JeJe »

Try

Code: Select all

sub AllNames
Call FindBoysNames 
Msgbox "Continue"
Call FindGirlsNames
end sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34617
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: "Umbrella macro" to call two other macros not working

Post by RoryOF »

If JeJe's suggestion works, the Msgbox line could probably be replaced with a delay of some sort; a quick method is a For Next loop which does nothing but consume time.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: "Umbrella macro" to call two other macros not working

Post by JeJe »

RoryOF - I don't know what the problem is exactly, but I tried a Wait statement which didn't work.

Davidcannon65 - if you make it as easy as possible for people to look at your problem you may get more help.

I had to create the attached document to test your problem... by copying and pasting your bits of code, looking at the search terms for sample items to put in the document, fix some " marks in the code. If you do all that it helps people help you...
Attachments
tmp.odt
(10.82 KiB) Downloaded 187 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Davidcannon65
Posts: 15
Joined: Sat Oct 02, 2021 12:34 pm

Re: "Umbrella macro" to call two other macros not working

Post by Davidcannon65 »

Thanks guys — and especially JeJe, who provided a solution that works perfectly.

I'm interested in Rory's idea, too. I've tried to look up how to implement the For Next loop, but in doing so I've screwed up big time. Any advice would be appreciated.

Also : is there a way to automate the "OK" command in the message box so that I don't have to click it? Thanks in advance!
OpenOffice 4.1.10 on Windows 8.1
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: "Umbrella macro" to call two other macros not working

Post by JeJe »

I was trying a couple of other things in that tmp document which weren't meant to be posted and didn't work either.

I tried the wait statement again though and it worked...

Code: Select all

sub AllNames
Call FindBoysNames 
wait 1000
Call FindGirlsNames
end sub
Edit: The 1000 is milliseconds = 1 second, you can change that number if a longer delay is needed.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Davidcannon65
Posts: 15
Joined: Sat Oct 02, 2021 12:34 pm

Re: "Umbrella macro" to call two other macros not working

Post by Davidcannon65 »

THANK YOU, JeJe! That works perfectly!
OpenOffice 4.1.10 on Windows 8.1
User avatar
RoryOF
Moderator
Posts: 34617
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Umbrella macro to call two other macros not wor

Post by RoryOF »

A For ...Next loop is simple

Code: Select all

Dim i as Long
Dim SomeCount as Long

SomeCount = 100000

For i = 1 to SomeCount
# do nothing
Next i

But JeJe's Wait 1000 is nicer. All we are trying to do is waste a little time so that the background code engine has stabilised.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Davidcannon65
Posts: 15
Joined: Sat Oct 02, 2021 12:34 pm

Re: [Solved] Umbrella macro to call two other macros not wor

Post by Davidcannon65 »

Thank you so much! Yes, I've used JeJe's code this time but I've copied your one down to study and use in future macros :-)
OpenOffice 4.1.10 on Windows 8.1
User avatar
robleyd
Moderator
Posts: 5084
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Umbrella macro to call two other macros not wor

Post by robleyd »

It may be worth knowing that the speed, or delay, of the for loop will depend on processor power and will vary between machines, where the wait command can be more precisely set.

And (no offense Rory) this is a very trivial use of for; it is mostly used for more complex work - see e.g. https://en.wikipedia.org/wiki/For_loop
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
User avatar
RoryOF
Moderator
Posts: 34617
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Umbrella macro to call two other macros not wor

Post by RoryOF »

robleyd wrote:I
And (no offense Rory) this is a very trivial use of for; it is mostly used for more complex work - see e.g. https://en.wikipedia.org/wiki/For_loop
I agree, but if one doesn't know about "wait", or if one is using a version of BASIC where "wait" is nor implemented, then doing this with For... Next can be useful. and it is obvious (I hope) that the extent of the delay can be changed by changing the parameter.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply