[Solved] Writer macro: Action based on paragraph style.

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

[Solved] Writer macro: Action based on paragraph style.

Post by kocj »

Hello community, I am new here, hopefully I have done everything right.

I am looking for help to create a macro that adds some bits of text, of a defined style, just before and after all paragraph of an other style. Lets assume that I have a paragraph style called mystyle. Now the macro should add @@.ta just before and @@ just after the paragraph, those bits of text should use myothersyle. The result should look like this.

Whitespace (Myothersyle)
@@.ta (Myothersyle)
Mstyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle
@@ (Myothersyle)
whitespace (Myothersyle)

To my understanding it should be possible to have a macro handling that. Till now I use two recoded macros and apply one before the paragraph and one after the paragraph. I works, but it is an error prone approach.

I am quite new to macros and do not have experience in programming at all. I would really appreciate that someone cold help me out with an example, that could adjust to my meeds later on. I tried to get some knowledge of the document from Andrews Pitonyaks BASIC-Makros für OpenOffice und LibreOffice. That did not really help me to go on with the macro.

Thanks

Kocj
Last edited by kocj on Thu Aug 23, 2018 9:52 am, edited 2 times in total.
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Writer macro: Action based on paragraph style.

Post by RoryOF »

Why use a macro?

Extension AltSearch
will do this.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

Re: Writer macro: Action based on paragraph style.

Post by kocj »

Thank you, I will try it out.
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

Re: Writer macro: Action based on paragraph style.

Post by kocj »

@ RoryOF

I have tried AltSearch now for a wile, I am very happy as it also solves an other solutions I was looking for. Thank you.

I did not find an option to group paragraphs of the same style. The reality i face looks more like:

Paragraph> Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle <Paragraph
Paragraph> Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle <Paragraph
Paragraph> Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mysty Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle <Paragraph
Paragraph> Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle Mystyle <Paragraph

Paragraph> OtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyle <Paragraph
Paragraph> OtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyleOtherstyle <Paragraph

I would like to markup a bundle of the same paragraph style only once. A lot of sentences are quite short, that makes it difficult to to do minor edits that might be needed once marked up. Is there any other way to achieve that.

The marked up documents will be displayed in a https://tiddlywiki.com later.
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Writer macro: Action based on paragraph style.

Post by RoryOF »

My immediate thought is that I would mark up the string of paragraphs this way
<beginmark>
Mystyle para
<endmark>
<beginmark>
Mystyle para
<endmark>
<beginmark>
Mystyle para
<endmark>

Now search and delete the sequence
<endmark>
<beginmark>

This will leave the above sequence as
<beginmark>
Mystyle para
Mystyle para
Mystyle para
<endmark>

which is I think what you require.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

Re: Writer macro: Action based on paragraph style.

Post by kocj »

@ RoryOF

sorry,I am not able to catch the sequence <endmark><beginmark>, not even if I try it on the example you provided. What do i do wrong? How to delete the mark and the paragraph too?
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Writer macro: Action based on paragraph style.

Post by RoryOF »

The Help file can be downloaded from (http://www.volny.cz/macrojtb/HelpAltSearch_en.html)p

I think you will have to read through this carefully and experiment with sequences to sort out your problem, if it is sortable.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

Re: Writer macro: Action based on paragraph style.

Post by kocj »

Yes, it's the same help page that comes up if pressed the ? in the extension. I have been studding for 8 hours the last tow days, to come that far. ;)

Just to get me running, a solution for this example would be enough.
My immediate thought is that I would mark up the string of paragraphs this way
<beginmark>
Mystyle para
<endmark>
<beginmark>
Mystyle para
<endmark>
<beginmark>
Mystyle para
<endmark>

Now search and delete the sequence
<endmark>
<beginmark>

This will leave the above sequence as
<beginmark>
Mystyle para
Mystyle para
Mystyle para
<endmark>

which is I think what you require
What to put in the search box, witch option to choose. Thanks
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Writer macro: Action based on paragraph style.

Post by RoryOF »

The AltSearch Help file says
List box 'Extended'

[::BigBlock::] - searches for a block of paragraphs (of unlimited length) delimited by some known text:

start[::BigBlock::]end – first, start is searched for, and when it is found, end is searched for. If both are found, the whole block between them is selected.

In the replace string you can use the parameters \b, & or \e for inserting the contents of start, found block of paragraphs, or end, respectively.

Limitation: In the initial and final strings you cannot use the || sign for multiple searching and replacing; see below.
This is probably the search construct you need.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
kocj
Posts: 19
Joined: Mon Aug 20, 2018 8:19 am

Re: Writer macro: Action based on paragraph style.

Post by kocj »

Found the solution, this will mark the sequenze.

Code: Select all

<endmark>\p<beginmark>
Thank you very much for your help.
Libreoffice 5.3 and 6.1 on Debian Stretch 9.5
Post Reply