Page 1 of 1

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

Posted: Tue Aug 22, 2017 6:50 pm
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?

Re: Match Individual Macro API with the API index?

Posted: Thu Aug 24, 2017 10:52 am
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

Re: Match Individual Macro API with the API index?

Posted: Thu Aug 24, 2017 2:21 pm
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?

Re: Match Individual Macro API with the API index?

Posted: Thu Aug 24, 2017 3:26 pm
by RPG
Hello

I'm waiting

Romke

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 7:25 am
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!

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 8:07 am
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

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 9:40 am
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.

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 10:47 am
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"

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 11:47 am
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.

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 1:35 pm
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

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 2:24 pm
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

Re: Match Individual Macro API with the API index?

Posted: Fri Aug 25, 2017 3:25 pm
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 ¶.

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

Posted: Fri Aug 25, 2017 3:53 pm
by rajibando
Dr. Hubert Lambert,
Are you Real?! Wow!