Can't an intuitive approach to API indexing be advised?

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

Can't an intuitive approach to API indexing be advised?

Post by rajibando »

My humble deference to Dr. Hubert Lambert!

Courtesy his macro code, my long-time need was immediately addressed.

The Question, also asked at the end with the predicted reply: Suppose if I didn't have the wonderful and complete macro-code, would I be able to reach these APIs to create the macro that defied most?

I studied his code. Needless to add, it speaks of his extreme depth of understanding regarding the workings of the macros!

Here is the list:
  • compareRegionEnds()
    createTextCursorByRange()
    doc
    doc.lockControllers()
    doc.UndoManager
    doc.unlockControllers()
    end if
    endchar
    ending
    ending
    Erl
    Err
    error
    goLeft()
    goRight()
    goto
    if
    lcase()
    leaveUndoContext()
    msgbox
    on
    oText
    para.End
    Sub
    then
    thiscomponent
    undos
    undos.enterUndoContext()
I searched for the list in the API, Global Index under home » api » docs » common » ref » index-files. What I found was that not all macros were in this global index.
Some, like undos were in the other index under home » api » docs » common » ref » com » sun » star » document The arrangement is not intuitive, and is supposed to pose problems for newbies like me.

Yeah, yeah, I know that I would immediately be advised to use Google to search the API index, either directly, or via the search panel. But isn't it kind of, er... , not-normal?!

Suppose if I didn't have the wonderful and complete macro-code, would I be able to reach these APIs to create the macro that defied most? Yeah, this also I know: depends on my particular need and searching according to that need.

Isn't this kind of indexing, "Learner-Averse"?
Last edited by rajibando on Mon Aug 28, 2017 9:03 am, edited 1 time in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Can't an intuitive approach to API indexing be advised?

Post by hubert lambert »

Hello,

I make an extensive use of hanya's MRI introspection tool to know about one object's methods and properties.

From there, and in order:
- the official uno api documention
- this forum
- the F1 help button
- Google & sons.

Have a nice day.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

Unfortunately, I use a Debian-type Linux system and I had downloaded that MRI tool upon advice from this very forum. But unfortunately, that MRI tool doesn't work. I will try to get it to work. My systems details are in my signature.

I feel honoured that you have taken some time to reply to my post.

May I learn what do you — and what should I — look for within this forum?

Regards
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Can't an intuitive approach to API indexing be advised?

Post by hubert lambert »

rajibando wrote:Unfortunately, I use a Debian-type Linux system and I had downloaded that MRI tool upon advice from this very forum. But unfortunately, that MRI tool doesn't work.
I use linux systems too, where MRI works fine. It is written in python: perhaps you should verify that the python script provider is installed alongside the program.
Do you use a distro-based version of Libreoffice or the official version?

You can also try Xray, which is another introspection tool, written in basic.
rajibando wrote:May I learn what do you — and what should I — look for within this forum?
Is this a trick question?
You'll find with MRI or XRay some methods or properties whose use is unclear: the forum contains today snippets and examples for most of them.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

That was not a trick question. You are so beyond me that I can't play games with you! I meant every bit of the query.

And my Libreoffice is a distros based version. Everything came pre-built with the Knoppix DVD Image.
A very robust system, survived infinite power-cuts and shutdowns! But things can be installed too, if one uses the HDD image instead of DVD to boot.

Are you God (Jesus-type) :o ? By some strange coincidence, MRI now runs in my system! I am presently learning to use it, particularly, the part, Use it from within a macro

But why the ellipses [ i.e., ... ] within the codes below? :

Code: Select all

Sub SomeSub()
  ...
  oMRI.inspect( theObjectThatYouWantToInspect )
  ...
End Sub
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Can't an intuitive approach to API indexing be advised?

Post by hubert lambert »

ellipsis = the real code, hidden just to highlight the usefull line.

Try this simple code:

Code: Select all

Sub SomeSub()
  doc = thiscomponent
  oMRI.inspect( doc )
End Sub
ThisComponent is a global variable available when you call a basic macro from a document context. That variable contains the main document object.
Have you read this: Basic Guide?
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't an intuitive approach to API indexing be advised?

Post by Villeroy »

You have to create your oMRI object before you can use it.

Code: Select all

Sub SomeSub()
REM the name "mytools.Mri" is defined by the MRI extension package:
oMRI = createUnoService("mytools.Mri") 
oMRI.inspect(oMRI) 'has its own properties and methods
  doc = thiscomponent
  oMRI.inspect( doc )
End Sub
Alternatively you can use the prepared Basic routine in Library "MRILIb" installed by the MRI extension.
If you have a look at that routine, you will notice that it does the same thing as the above routine.

Code: Select all

Sub SomeOtherSub()
GlobalScope.BasicLibraries.loadLibrary("MRILib")
mri ThisComponent
End Sub
In most cases I call MRI from menu:Tools>Add-Ins>MRI.
Quite often I inspect event structures of some script event. Instead of assigning my own macro to the script event, I first assign Basic MRILIb.Module1.Mri to the event in question. Then you get the full set of passed arguments in the event struct with the "Source" property representing the calling object.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

Dear Mr. Villeroy,
I am already all ears for the master! So could you please excuse me? I can't pay attention to many at once! I am a very poor pupil! I am so sorry! I have no intent to hurt you. I respect your intent to offer support and your great experience as a volunteer with 30K posts. So even if I wanted, I am nowhere in comparison to your stature!
Thank you for understanding.
Last edited by rajibando on Mon Aug 28, 2017 3:20 pm, edited 1 time in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't an intuitive approach to API indexing be advised?

Post by Villeroy »

May be you are poor. That would be the best incentive to strive for more. But you better not pretend being dumb.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

No, Sir, Mr. Villeroy! I am slow! I pick up the tricks of the trade rather slowly. I would therefore honestly request your forgiveness.
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

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

hubert lambert wrote: ... That variable contains the main document object.
Have you read this: Basic Guide?
Yes, I am reading it.
Is there a complete API reference VBA for MsOffice available offline in ebook format? Apparently, it is available for reading offline via Google Search of

Code: Select all

Download Office 2013 VBA Documentation from Official Microsoft
and subsequent downloading, in chm format.
Last edited by rajibando on Fri Sep 01, 2017 1:18 pm, 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

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

hubert lambert wrote:...
hanya's MRI introspection tool
From there, and in order:
- the official uno api documention
- this forum
- the F1 help button
- Google & sons.
Yes, Master! Understood what you had said earlier and above, with experience.

But what I found differed somewhat from your experience, may be because you were already an accomplished VBA programmer, while I learnt only rudimentary C and now, learning Java.
After (1) installation of Hanya's MRI Introspection Tool, (2) selection of the macro's APIs, then pressing F1 to learn more about those macros, (3) then even more from MRI tool, (4) then the Apache API index, and then (5) Google (& sons not yet arrived in the Management Board).

But not all codes are accessed thus.
For example, let us look at this macro:

Code: Select all

Sub InitializeMRI()
  Globalscope.BasicLibraries.LoadLibrary("MRILib")
  oMRI = CreateUnoService("mytools.Mri")
End Sub
In the Basic Editor I double click every code-bit and select each. I press F1. For some I find no info. I copy and paste in MRI's Search TextBox at the lower right. I find no info. Eg., for Globalscope I find no entry, for BasicLibraries, find no entries, For CreateUnoService, find no entries, and so on, with either F1 or entry into MRI search box.

Is there a way to select a code bit/method and have it checked via MRI? Where am I going wrong?

Also:
What does this code do w.r.t. all its methods and APIs?:

Code: Select all

Sub a_onClick_Handler(oEvent As Object)
  Dim oForm As Object
  oMRI.inspect(oEvent.Source)
  oForm = oEvent.Source.Model.getParent()
  oMRI.inspect(oForm)
How can each method and APIs be inspected in MRI and StarOffice API Index?

Example, I searched and found:
[1] getParent
XElement
getParent();

Description
Gets the parent context.
Returns
parent context

[2] http://www.openoffice.org/documentation ... icXref.pdf
... It is possible to have the one routine called by events for more than one control, to know
which control called the event use an event parameter as shown is this example that could
be used as the associated code for the initiate event for the TabForPage button controls in
the above example:

Code: Select all

Sub Page_Buttons_Click(oEvent)
with oDialog
'Change state of all tab controls
for i = 1 to 2
.getControl("TabForPage" & i).Model.State = 0
next
'Change the state of the one that was pressed
oEvent.source.model.state = 1
[3] oEvent, oForm, etc., what are they -- Variables? Where can I find them?
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't an intuitive approach to API indexing be advised?

Post by Villeroy »

GlobalScope, StarDesktop and ThisComponent are not defined in the UNO API. They belong to the StarBasic language.

GlobalScope belongs to the Basic language only. It refers to the collection of global Basic libraries that appear as "My Macros" in the user profile folder and "LibreOffice Macros" in the installation folder. Without GlobalScope you refer to libraries within ThisComponent.

StarDesktop and ThisComponent are Basic simplifications for the com.sun.star.frame.Desktop and for the "current document". The current document is either the document where this Basic code is stored or (if this code is stored in GlobalScope) the currently active document.

If you want to learn programming, do yourself a favour and do it with a computer that does not have any office suite or Basic language installed. This API is far too complicated for beginners and Basic is a dead language with no future.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

Mr. Villeroy, Sir!
I am sure the master will come up with a shortcut for me. I will await his instruction.
Thanks for your post.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't an intuitive approach to API indexing be advised?

Post by Villeroy »

A shortcut for reading and excecizing? Don't think so.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can't an intuitive approach to API indexing be advised?

Post by Zizi64 »

I will await his instruction.
Here they are:

Read & learn! (there are lots of descriptions and example code snippets)
Try it the learned things! (you must to practice the learned things)
Make your own simple practice projects! (nobody can give you experience and skill)
Finally:
Ask, when you have your own macro project, and you can not know the next step.

+1:
Be more independent, self-sufficient!
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: Can't an intuitive approach to API indexing be advised?

Post by rajibando »

To Dr. Hubert Lambert,
Master, could you kindly peruse the post of Thu Aug 31, 2017 6:25 pm once again, particularly, this part? :
Is there a way to select a code bit/method and have it checked via MRI? Where am I going wrong?

Also:
What does this code do w.r.t. all its methods and APIs?:

Code: Select all

Sub a_onClick_Handler(oEvent As Object)
  Dim oForm As Object
  oMRI.inspect(oEvent.Source)
  oForm=oEvent.Source.Model.getParent()
  oMRI.inspect(oForm)
Mr. Villeroy has given some inputs, and I understand it better now!

MRI doesn't help with StarBasic libraries, methods, objects and APIs, does it? It helps with UNI extensions, perhaps?Where can I find a complete reference for StarBasic methods, objects and APIs? I have one, but it doesn't say explicitly that it is the complete reference!
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
Post Reply