Working with MRIOne of the best and at the same time most irritating things of MRI is that it has a menu option to generate code in different scripting languages. This sounds very promising if only you could figure out where to find this generated code.

- MRI Initial window layout
The solution is to hold the mouse pointer above the upper border of the MRI status line. The pointer will change to a symbol that indicates that you can drag a border with it. And that's the whole clue: The initial size of the code window is zero and you just need to increase it a bit.

- MRI Code window visible
Whenever you double click on a Method or Property the code window will show some more lines of code (the ones that are needed to get from the initial object to the object of this property or this method). At the same time the middle window with all the properties and methods will change to the properties/methods of the new object. If you double click on a method that requires parameters (as for the above shown
goDown) MRI will popup a dialog and ask you for a value for each one of the required parameters.
If you can't guess what a method is doing by its name or if you need more detailed information on a method you can click the big
IDL Ref. button and your browser will take you to the right place in the API documentation. In the above case with the
goDown selected this would be:
http://www.openoffice.org/api/docs/comm ... tml#goDownIf you have got lost in the object hierarchy after clicking on some properties or methods you have always the chance to get back to your initial object (or any other object that you selected on your way) with the dropdown box in the second row.

- MRI Details
As you might see in the above image the layout in Windows-7 has some flaws: Instead the 4 choices (
Properties, Methods, Interfaces and SupportedServices) the multi-selection shows only the first two of them together with some ugly scrollbars. Ugly or not, the scrollbars ensure that you can also get two these to other (hidden) features.
Edit: This inconsistency is not a problem of Windows 7. It is related with the fact that the monitor that I use together with the Windows 7 OS has a very high pixel density and is still rather small. The standard font was very hard to read and was therefore changed to a larger font. If you continue to use the standard font set you will see all 4 choices of the multiselection. The problem appears only if you have a larger font and the space in the multiselect box is therefore only enough for 2 sections in the larger font but not for all 4. |
With the code window MRI can serve as a macro recorder, that records real API functions in contrary to the standard macro recorder of OpenOffice that only records dispatcher calls. But MRI doesn't record what you are doing (your keystrokes and mouse-clicks) in one of the OOo Applications, but your clicks in MRI. This means if you want to create a macro that changes the name of the spreadsheet on which your cursor is you select "MRI <- Selection" and have the current cell as initial Target in MRI. You have to search through the methods and find a
getSpreadsheet, that sounds promising to you. After a double click on it you see that the text box at the top of MRI says "com.sun.star.sheet.XSpreadsheet", which is a good sign. So you browse again through the list of methods until you get to 's' and
setName. Another double click brings up a dialog where you can type in a new name. You type "aNewName" and you will see a text box dialog saying void (because the method did not return anything), but the name of your spreadsheet tab at the bottom has changed to "aNewName".
A useful feature of MRI is that you can build a diff between two states/snapshots of a property. This is described very well in the built-in help under the section title "Tips":
MRI documentation wrote:If you want to change a property of a object but you do not know the name of the property. However you can change it through UI.
This enables you to record GUI operations indirectly. The diff will point you to the property that is changed and that you need to use. But you still have to select this property that you see highlighted in the diff in a second pass in MRI to have it recorded.
Use it from within a macroThe above mentioned builtin online documentation has a detailed section about how to start MRI from macro code: "How to Run MRI". It shows how to do this with most of the languages that are supported by OOo. For the sake of brevity I will show here only how to do it with OOo Basic:
- Code: Select all Expand viewCollapse view
Global oMRI As Object
Sub InitializeMRI()
Globalscope.BasicLibraries.LoadLibrary("MRILib")
oMRI = CreateUnoService("mytools.Mri")
End Sub
' and later anywhere in your Subs, Functions ...
Sub SomeSub()
...
oMRI.inspect( theObjectThatYouWantToInspect )
...
End Sub
Sub a_onClick_Handler(oEvent As Object)
Dim oForm As Object
oMRI.inspect(oEvent.Source)
oForm = oEvent.Source.Model.getParent()
oMRI.inspect(oForm)
Before you can use MRI you have to load its Basic wrapper into the GlobalScope of the Basic Libraries. That's done with the first line of
InitializeMRI. The next line creates the MRI Uno-Service and puts it into a global variable. This has the advantage that it is available in all subroutines and functions in the same macro file simply by executing
InitializeMRI once before you run your other macro code.
There is one caveat and this is that any global variables will be reset if the file where the variable resides is re-compiled. Because you are typically using MRI when developing a new macro, it is quite common that you start MRI in the macro code, click your way around in MRI until you have found the property or method you are looking for, finish the macro and make the appropriate changes in you macro code. You run your code again, maybe with a different initial target for MRI (because you got some steps further) ... and oops you get can an error in the line with
oMRI.inspect. The reason is, after your changes to the macro, OOo needed to re-compile the macro file and the global variable
oMRI lost its value and was reset to NULL/nothing. In other words most of the times you have to call
InitializeMRI before you run your macro. After you forgot this two or three times you are fed up with this and you will put a
Call InitializeMRI at the beginning of the Sub you are working on.
Other threads related with MRIVilleroy lists 8 advantages of MRI compared to Xray:
[Solved] Combobox and controls in formsHanya who developed MRI on instantiating services:
Select complete columns and object model documentationArineckaig on using MRI with forms and/or form controls:
[Base] Call MRI on forms or form controls from form documentArineckaig has also written a step by step guide on how to navigate with MRI through the object hierarchy of the UNO objects. This .odt Writer file is uploaded to the forum and can be accessed as:
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.