Can Xray be used in a Python script?

Is it possible to call Xray from within a Python script and if so how is it done?

See 5.1:

It’s better MRI: MRI - UNO Object Inspection Tool | Apache OpenOffice Extensions

Work fine in LibreOffice, and you call into Python scripts…

Best regards

This works for Xray:

# Xray python script 
import uno
def xray_test():
    ctx = uno.getComponentContext()
    smgr = ctx.ServiceManager
    document = XSCRIPTCONTEXT.getDocument()
    xray(smgr,ctx, document)

def xray(smgr, ctx, target):
    mspf = smgr.createInstanceWithContext("", ctx)
    script_provider = mspf.createScriptProvider("")
    script = script_provider.getScript("")
    script.invoke((target,), (), ())

Edit: Corrected to include uno & smgr. Tested from user directory.