OpenOffice BASIC API viewer

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Evgeniy
Posts: 43
Joined: Thu Jan 09, 2020 9:31 pm
Location: Russia

OpenOffice BASIC API viewer

Post by Evgeniy »

Code:

Code: Select all

Function Replace(Source As String, Search As String, NewPart As String)
	Dim Result As String
	Result = join(split(Source, Search), NewPart)
	Replace = Result
End Function

Sub Show(obj_ As Object, type_ As Integer)
	Dim str As String
	
	if type_=0 then str = obj_.DBG_Methods
	if type_=1 then str = obj_.DBG_Properties
	if type_=2 then str = obj_.DBG_SupportedInterfaces
	
	str = Replace(str,Chr(10),"")
	str = Replace(str,";",";"&Chr(10))
	str = Replace(str,":",":"&Chr(10)&Chr(10)&" ")
	str = Replace(str,"Sbx","")	
	
	Dim s()
	s=Split(str,";")
	iter=0
	For i=LBound(s) to UBound(s)
		if type_=1 then
			s(i)=Replace(s(i),";","")
			if InStr(s(i),"BOOL")>0 then s(i)=Replace(s(i)," BOOL ","")&" As Boolean"
			if InStr(s(i),"INTEGER")>0 then s(i)=Replace(s(i)," INTEGER ","")&" As Integer"
			if InStr(s(i),"DOUBLE")>0 then s(i)=Replace(s(i)," DOUBLE ","")&" As Double"
			if InStr(s(i),"STRING")>0 then s(i)=Replace(s(i)," STRING ","")&" As String"
			if InStr(s(i),"OBJECT")>0 then s(i)=Replace(s(i)," OBJECT ","")&" As Object"
			if InStr(s(i),"LONG")>0 then s(i)=Replace(s(i)," LONG ","")&" As Long"
			if InStr(s(i),"ARRAY")>0 then s(i)=Replace(s(i)," ARRAY ","")&" As Array"
		endif
		's(i)=s(i)&"+"
		iter=iter+1
		if iter>30 then
			iter=0
			s(i)=s(i)&">>>"
		end if
	Next i
	str=Join(s)		
		
	s=Split(str,">>>")	
	For i=LBound(s) to UBound(s)
		msgbox "Page "+i+" of "+UBound(s)+Chr(10)+Chr(10)+s(i)
	Next i		

End Sub
Using:

Show(obj_ As Object, type_ As Integer)

obj_= any object as Frame, Imgae, etc.

type_ = is what we want to see:
0 - show all object methods
1 - show all object propertys
2 - show all object interfaces

Code: Select all

	Doc = ThisComponent
	Show(Doc,0)
Result:
Attachments
api.png
OpenOffice 4.1.7 OS: Win10 x32 + Win10 x64
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OpenOffice BASIC API viewer

Post by Villeroy »

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
Evgeniy
Posts: 43
Joined: Thu Jan 09, 2020 9:31 pm
Location: Russia

Re: OpenOffice BASIC API viewer

Post by Evgeniy »

Yes, I saw this tool it is bulky. I still do not understand how to use it. Therefore, I wrote this function. So far, everything suits me.
OpenOffice 4.1.7 OS: Win10 x32 + Win10 x64
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: OpenOffice BASIC API viewer

Post by JeJe »

Once MRI is installed and the library is loaded... its VERY easy to use. You just write MRI followed by the object you want inspected. eg

MRI ThisComponent

will give all the properties and methods and so on of ThisComponent and let you navigate from there to inspect other related objects. Instead of ThisComponent you can put any object or variable...

Edit: and you can put that line anywhere in your code... and an MRI dialog will pop up with all that information at that point... and your code will resume without halting
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OpenOffice BASIC API viewer

Post by Villeroy »

That's why I posted the tutorial. Trying to write macros without MRI (or XRay at least) makes no sense. Most macro related questions on this forum can be answered with a little help from MRI. It is the first thing I call before writing anything.

Without writing any code
menu:Tools>Add-ins>Mri inspects the current component.
menu:Tools>Add-ins>"Mri <-- Selection" inspects the current selection.
If you assign some object's event to Basic macro MyMacros>MriLib>Module1>Mri then you get the inspection window for the calling event.
Just double-click one the line describing the property or method you are interested in.

When writing code:
This is an easy method to inspect your objVariable:

Code: Select all

  oMRI = CreateUnoService( "mytools.Mri" )
  oMRI.inspect( objVariable )
or this:

Code: Select all

GlobalScope.BasicLibraries.loadLibrary("MRILib2")
mri objVariable
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: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: OpenOffice BASIC API viewer

Post by Zizi64 »

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.
Post Reply