[Closed] Match Individual Macro API with the API index?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

[Closed] Match Individual Macro API with the API index?

Post by rajibando »

I have two macros, courtesy Hubert Lambert. I post them here:

Code: Select all

rem ************************************************

Sub Check
on error goto ending:
    doc = thiscomponent
    doc.lockControllers()
    undos = doc.UndoManager
    undos.enterUndoContext("Format numbered paragraphs")

    rajibando_find_and_remplace(doc.Text)

  ending:
    if Err then
        msgbox("Error #" & Err & ": " & Error + chr(13) + "At line: " + Erl + chr(13), 16 ,"Error")
    end if
    undos.leaveUndoContext()
    doc.unlockControllers()
    on error goto 0
End Sub
rem *****************************************
&

Code: Select all

rem **************************************
sub rajibando_find_and_remplace(T)
    do
        for each para in T
            if T.compareRegionEnds(T, para) = 0 then
                exit sub
            end if
            c = T.createTextCursorByRange(para.End)
            c.goRight(2, True)
            firstchar = mid(c.String, 2, 1)
            Print(firstChar)
           if not isnumeric(firstchar) then
                c.String = chr(10) & firstchar
                exit for
            end if
        next para
    loop
end sub
rem *****************************************    
Not that the macro works as intended, but at least, it is definitely a positive step towards progress!
I now wish to read about each individual API, e.g., what are their scopes? what do they do? etc.
I referred to the Overview (Java UNO Runtime Reference) but couldn't locate any of the APIs in this macro with there.
Obviously, because these are components of StarBasic macro API, if I am not mistaken. Now how do I access the StarBasic APIs?: I've read the Wikipedia's OpenOffice Basic entry. And from there to a few links, like http://wiki.services.openoffice.org/wik ... pers_Guide, http://wiki.services.openoffice.org/wik ... ASIC_Guide, http://www.pitonyak.org/oo.php and a couple of more.
A huge reading list, but will take some time.
Any tip?
Last edited by rajibando on Fri Sep 08, 2017 1:08 pm, edited 6 times in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Match Individual Macro API with the API index?

Post by RPG »

Hello
rajibando wrote:Any tip?
I think go back to the basics of your problem. Describe somewhere what is your problem.I have read all your post on this forum and I have the idea you have not describe your problem. It means not I have a solution.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Match Individual Macro API with the API index?

Post by rajibando »

... I have read all your post on this forum ...
Wow, you have? It's my honour!
Perhaps the dates of the threads' creations could help?
Last edited by rajibando on Fri Aug 25, 2017 9:43 am, edited 1 time in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Match Individual Macro API with the API index?

Post by RPG »

Hello

I'm waiting

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Match Individual Macro API with the API index?

Post by rajibando »

Seriously?
You read all my posts and did not still know what is expected? I am beginning to become uneasy.
There are many who require your help. Better invest your time helping them!
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Match Individual Macro API with the API index?

Post by RPG »

Hello

I think do tell what you want in an other way. The way you did told it now did not help you. It brings you not a solution. Maybe you want only edit text

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Match Individual Macro API with the API index?

Post by rajibando »

RPG, I am sorry I did not interpret your post correctly.
There is really no need for me to rephrase. Just a chronology will suffice.
The first advised macro is here:

Code: Select all

rem **********Code Courtesy: Librebel*****************
    Function Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds() As Long
    REM Replaces all Paragraph breaks with a Linefeed character within the current Writer document.
    REM Returns: the number of found/replaced occurrences.
        Dim oReplace as Object
        oReplace = ThisComponent.createReplaceDescriptor()
        oReplace.setSearchString( "[a-z,A-Z,0-9]$" )
        oReplace.setReplaceString( "&" + chr(10) )
        oReplace.SearchRegularExpression = True
        Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds = ThisComponent.replaceAll( oReplace )
    End Function
There are three files,Test.odt, tested.odt and WhatIWant.odt, here. Please look at the snapshots and their names as clues, here.
original.jpeg
After_Macro_is_run.jpeg
What_I_actually_want.jpeg
If you notice carefully, you shall see that After_Macro_is_run.jpeg has removed the last character even though relevant ¶ (paragraph mark) were replaced by ↲ (new line) at appropriate places.
Now I have this new macro above what does some work, but not exactly what I want.
I want to replace `a-z,A-Z,0-9]$` where the ¶ (paragraph mark) replaced by a ↲ (new line) satisfying the condition. While for the rest, such as ".", "?" and "!" and "!" at the end of a paragraph, the ¶ (paragraph mark) remains ¶.
And the resultant code that is to be worked on accordingly is already above.
Will this explanation be sufficient?
In the end, I would need to learn to match the APIs in the code, such as of the macro earlier in this thread, with the work they do, in the reference index of Apache OpenOfficeOrg API. Explicitly,
  • Check
    doc
    doc.lockControllers()
    doc.UndoManager
    doc.unlockControllers()
    end if
    ending
    ending
    Erl
    Err
    error
    goto
    if
    msgbox
    on
    then
    thiscomponent
    undos
    undos.leaveUndoContext()
    Sub
... and so on.
Some of them I obviously know, but I would need to know them as regards to their exact scope of applicability.
Was I able to address your concerns?
I apologise once again.
Last edited by rajibando on Fri Aug 25, 2017 3:38 pm, edited 2 times in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Match Individual Macro API with the API index?

Post by Zizi64 »

Code: Select all

        oReplace.setSearchString( "[a-z,A-Z,0-9]$" )
        oReplace.setReplaceString( "&" + chr(10) )
Your macro never will work correctly.
The first line of the quoted code means: You want find all of the [a-z,A-Z,0-9] alphanumerical characters at the paragraph end sign, but it not mean anyway: "the alphanumerical characters and the paragraph end sign".

Therefore it will re-pasted the original string part + a LineFeed character in front of the unchanged paragraph end sign.

And the text line with the line feed sign AND the next empty line mean (after the replace procedure): theese lines (that two lines) mean ONE paragraph only.
There is not any EMPTY paragraph in the result -> you can not remove those non-existing "empty paragraphs". Those just seems as "empty paragraphs"
Last edited by Zizi64 on Fri Aug 25, 2017 2:26 pm, edited 1 time in total.
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.
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Match Individual Macro API with the API index?

Post by hubert lambert »

rajibando wrote:I want to replace `a-z,A-Z,0-9]$` with ¶ (paragraph mark) replaced by ↲ (new line) satisfying the condition. While for the rest, such as ".", "?" and "!" the ¶ (paragraph mark) remains ¶ (paragraph mark).
I think it's a bit more clear: are you searching for end of sentence marks ? I've read elsewhere about paragraphs starting with number, but I probably read wrong.
Anyway, here's a new attempt to meet your last explanations.
Attachments
rajibando.odt
v2 (correct script error)
(13.61 KiB) Downloaded 271 times
Last edited by hubert lambert on Fri Aug 25, 2017 1:57 pm, edited 2 times in total.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Match Individual Macro API with the API index?

Post by RPG »

Hello

Zizi64 and hubert lambert make already clear what they found of your new explanation. I think you do not add any thing new. I want read some thing like:
  • I writing poems and it is difficult for me to format the text in a way I want have
  • I have a list of names and for some reasons explaned by you I want that formatting
  • Make your own explanation
You example with fantasy words make not any thing clear about the text you work with. There is no reason to tell your secrets but good examples will always help. Zizi64 make more then once clear what is possible new line and paragraphs. He knews it better as me.
I want only make clear to you describe your problem in an other way.

I'm not good in text macro's but I knew from my coding experience that what you want do is difficult there you can not do it with a standard service or interface.

About learning programming
When you want program the API you need a detailed knowledge about the normal working of OpenOffice. You need a detailed knowledge how you can insert and work with text and paragraphs. You prove several time you have not. You can not study the API without that knowledge.

So start first learning how OpenOffice is working without any macro and explain in normal words what are you doing. I have the idea macro's are to difficult for you, but you can continue:
Learning a script language of your choice.
Learning Basic for the examples of this forum.
Learning the Introduction for the API.
Learning all service, interfaces, methodes, properties, strucs and more
Bring together all the pieces of those things there it is all separated stuff.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Match Individual Macro API with the API index?

Post by Zizi64 »

Apache OpenOfficeOrg
There is not such organisation or product name.

There were / there are:

StarOffice
OpenOffice.org
Sun OpenOffice
Oracle OpenOffice
Apache OpenOffice
LibreOffice

...see the chart:
https://en.wikipedia.org/wiki/LibreOffice#History
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.
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Match Individual Macro API with the API index?

Post by rajibando »

For Dr. Hubert Lambert,
I think it's a bit more clear: are you searching for end of sentence marks ? I've read elsewhere about paragraphs starting with number
I have made a minor error. I have edited the post, to which you responded just now, to express myself better for you. I apologise for creating hindrances for your attempts to help me.
"with" is replaced by "where"
& the phrase added:
and "!" at the end of a paragraph,
The finalised request:
I want to replace `a-z,A-Z,0-9]$` where the ¶ (paragraph mark) is replaced by a ↲ (new line) satisfying the condition. While for the rest, such as ".", "?" and "!" at the end of a paragraph, the ¶ (paragraph mark) remains ¶.
Last edited by rajibando on Sat Aug 26, 2017 5:44 am, edited 1 time in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

[Closed]Re: Match Individual Macro API with the API index?

Post by rajibando »

Dr. Hubert Lambert,
Are you Real?! Wow!
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
Post Reply