Top > OOo > Ext > MRI > Documentation > RunMRI

How to Run MRI Edit

MRI can be called from any languages and Add-Ons menu entries.

Run MRI from Languages Edit

If you want to use MRI from languages that you want to use, instantiate "mytools.Mri" service. And call inspect method with a target as its argument.

inspect is a method of interface and you may query this interface depending on the language that you use. Normal inspect method returns interface and MRI's it returns the same interface taken from service.

If you pass non-UNO objects to inspect method, MRI does not work correctly. inspect( [in] any aObject ) Basic Edit

MRI.oxt package includes MRILib library of OOo Basic. And Mri subroutine placed in the MRILib library helps you to call MRI from OOo Basic easily. Pass an object to the Mri like written below (in this case, ThisComponent is passed as a target).

Mri ThisComponent

An argument of Mri subroutine is optional. When Mri called without an argument, Mri subroutine passes StarDesktop to MRI as a target using OOo Basic runtime function.

Mri  ' StarDesktop is passed to MRI by Mri subroutine

Before you call Mri first time, need MRILib loaded.

Globalscope.BasicLibraries.LoadLibrary( "MRILib" )

Then you can call MRI like written below from OOo Basic without the Mri helper subroutine.

oMRI = CreateUnoService( "mytools.Mri" )
oMRI.inspect( MriTargetObject )

The control of the program is returned after Mri subroutine passes to service of MRI. Therefore you need to breakpoints of Basic IDE debugger if you want to inspect a object temporary created or you want to inspect the target well.

If you passed to a target to Mri that is part of a document opened on the StarDesktop and it lives after your Basic code finished, you can travel in it (passed value is a copy of the target but references are the same them of the original target).

BeanShell Edit

This is an example of how to use MRI from BeanShell macros.


XComponentContext xContext = XSCRIPTCONTEXT.getComponentContext();
XMultiComponentFactory xMCF = xContext.getServiceManager();
try {
  oMRI = xMCF.createInstanceWithContext( "mytools.Mri", xContext );
} catch ( e) {
  System.out.println( e.Message );
XIntrospection xIntrospection = (XIntrospection) UnoRuntime.queryInterface( 
                                       XIntrospection.class, oMRI );
Object oDoc = XSCRIPTCONTEXT.getDocument();
Object oIAccess= xIntrospection.inspect(oDoc);

JavaScript Edit

This code is an example to run MRI from Javascript macro.


oDoc = XSCRIPTCONTEXT.getDocument();

xContext = XSCRIPTCONTEXT.getComponentContext();
xMCF = xContext.getServiceManager();
oMRI = xMCF.createInstanceWithContext("mytools.Mri", xContext);
xIntrospection = UnoRuntime.queryInterface(XIntrospection, oMRI);

Java Edit

Looks similar in the BeanShell.


try {
 Object oMRI = xMultComponentFactory.createInstanceWithContext( 
     "mytools.Mri", xContext );
 XIntrospection xIntrospection = (XIntrospection) UnoRuntime.queryInterface(
    XIntrospection.class, oMRI);

} catch ( e) {

Python Edit

This example shows how to use MRI from Python macro.

def Mri_test():
   ctx = XSCRIPTCONTEXT.getComponentContext()
   document = XSCRIPTCONTEXT.getDocument()

def mri(ctx, target):
   mri = ctx.ServiceManager.createInstanceWithContext(

And you can also use MRI through Python-bridge.

import uno
def connect():
       localctx = uno.getComponentContext()
       resolver = localctx.ServiceManager.createInstanceWithContext(
       ctx = resolver.resolve(
       return None
   return ctx
def mri(ctx, target):
   mri = ctx.ServiceManager.createInstanceWithContext(

if __name__=="__main__":
   ctx = connect()
   if ctx == None:
       print "Failed to connect."
       import sys
   smgr = ctx.ServiceManager
   desktop = smgr.createInstanceWithContext("",ctx)
   model = desktop.loadComponentFromURL("private:factory/scalc","_default",0,())

VB Script Edit

MRI easily can be run from automation.

Set oSM = WScript.CreateObject("")
Set oDesktop = oSM.createInstance("")

Dim aArgs() 
Set oDoc = oDesktop.loadComponentFromURL("private:factory/scalc","_blank",0,aArgs)
Set oMRI = oSM.createInstance("mytools.Mri") 

ooRexx Edit

ooRexx (with Vienna BSF4Rexx).

/*  */
xScriptContext = uno.getScriptContext()
xContext = xScriptContext~getComponentContext()
xServiceManager = xContext~getServiceManager()

oDoc = xScriptContext~getDocument

oMRI = xServiceManager~createInstanceWithContext("mytools.Mri", xContext)

::requires UNO.CLS

Run MRI from Add-Ons Menu Edit

MRI can be run from Add-Ons menu entry. Choose Tools - Add-Ons - MRI entry, the MRI window opens with a return value of the getCurrentComponent method of the interface of the service as its target.

MRI is executed with the current document as its target. It can be written by OOo basic like below.

oDesktop = CreateUnoService("")
oTarget = oDesktop.getCurrentComponent()
Mri oTarget

Run MRI from Add-Ons Menu with a Selection Edit

Choose- Tools - Add-Ons - "MRI <- selection" menu entry, MRI window opens with selected object as its target. In the OOo Basic, it is taken like below.

oDesktop = CreateUnoService( "" )
oTarget = oDesktop.CurrentComponent.getCurrentSelection()
Mri oTarget ' using Mri subroutine of the MRILib 
oMri = CreateUnoService("mytools.Mri")

You can use this menu to get information of an object that can be selected placed on the document (e.g. Writer: texts, text objects or ..., Calc: a cell, a cellrange, cellranges, drawing objects or ..., Draw: ....).

When you select a drawing object and call MRI with a selection, drawing objects are collected in service. So you need to get a desired object from it using getByIndex method. Some selectable objects are the same like the drawing objects.

Creating Custom Menu Entries Edit

If you want to add menu entries or toolbar buttons of MRI, use this URL.


If current argument is passed, MRI gets CurrentComponent of Desktop as its target. MRI run with a selection of a CurrentComponent of the Desktop.


Run from Command Line Edit

You can run MRI from the command line using the same URL.

>soffice service:mytools.Mri?none

Use none as its argument to run MRI with as its target.

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes