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 com.sun.star.beans.XIntrospection interface and you may query this interface depending on the language that you use. Normal inspect method returns com.sun.star.beans.XIntrospectionAccess interface and MRI's it returns the same interface taken from com.sun.star.beans.Introspection service.

If you pass non-UNO objects to inspect method, MRI does not work correctly.

com.sun.star.beans.XIntrospectionAccess inspect( [in] any aObject )

OpenOffice.org 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.

import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.beans.XIntrospection;
//import com.sun.star.beans.XIntrospectionAccess;

XComponentContext xContext = XSCRIPTCONTEXT.getComponentContext();
XMultiComponentFactory xMCF = xContext.getServiceManager();
try {
  oMRI = xMCF.createInstanceWithContext( "mytools.Mri", xContext );
} catch (com.sun.star.uno.Exception 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.

importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.beans.XIntrospection);

oDoc = XSCRIPTCONTEXT.getDocument();

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

Java Edit

Looks similar in the BeanShell.

import com.sun.star.beans.XIntrospection;

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

 xIntrospection.inspect(oShape);
} catch (com.sun.star.uno.Exception e) {
  System.err.println();
}

Python Edit

This example shows how to use MRI from Python macro.

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

def mri(ctx, target):
   mri = ctx.ServiceManager.createInstanceWithContext(
       "mytools.Mri",ctx)
   mri.inspect(target)

And you can also use MRI through Python-bridge.

import uno
 
def connect():
   try:
       localctx = uno.getComponentContext()
       resolver = localctx.ServiceManager.createInstanceWithContext(
           "com.sun.star.bridge.UnoUrlResolver",localctx)
       ctx = resolver.resolve(
           "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
   except:
       return None
   return ctx
 
 
def mri(ctx, target):
   mri = ctx.ServiceManager.createInstanceWithContext(
       "mytools.Mri",ctx)
   mri.inspect(target)

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

VB Script Edit

MRI easily can be run from automation.

Set oSM = WScript.CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oSM.createInstance("com.sun.star.frame.Desktop")

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

ooRexx Edit

ooRexx (with Vienna BSF4Rexx).

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

oDoc = xScriptContext~getDocument

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

::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 com.sun.star.frame.XDsktop interface of the com.sun.star.frame.Desktop 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("com.sun.star.frame.Desktop")
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( "com.sun.star.frame.Desktop" )
oTarget = oDesktop.CurrentComponent.getCurrentSelection()
Mri oTarget ' using Mri subroutine of the MRILib 
'or
oMri = CreateUnoService("mytools.Mri")
oMri.inspect(oTarget)

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 com.sun.star.drawing.SvxShapeCollection 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.

service:mytools.Mri?current

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

service:mytools.Mri?selection

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 com.sun.star.frame.Desktop 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