[Solved] Unable to call a Python extension macro from Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
LibreOfficiant
Posts: 12
Joined: Wed Jan 25, 2017 9:36 pm

[Solved] Unable to call a Python extension macro from Basic

Post by LibreOfficiant »

Hi,

As per OpenOffice specs, calling a Python extension macro from Basic is possible. I have been unable to do so and may surely be doing something wrong.

I am linking a Writer doc holding example code and instructions for anyone to x-check.

Thanks in advance for your assistance in that matter.
Last edited by LibreOfficiant on Sat Oct 27, 2018 12:08 pm, edited 1 time in total.
libO 5.4 64bit, (PortableApps: libO 6.0, aOO 4.1, OOo 3.2 32bit) on Win7/Win10 x64 | aOO 4.1.x & libO 5.4.x on Mint 18 Sarah & OSX 10.9 Mavericks x64
Python toolbox: Geany, PyCharm and APSO, MRI extensions..
https://wiki.documentfoundation.org/Macros/Design_Guide
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Unable to call a Python extension macro from Basic

Post by hubert lambert »

Hi,

When calling an embedded python script, you need to pass the document model as argument to the method createScriptProvider:

Code: Select all

    doc = thiscomponent
    uri = "vnd.sun.star.script:apso_utils.py$console?language=Python&location=document"
    mspf = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
    msp = mspf.createScriptProvider(doc)
    script = msp.getScript(uri)
    script.invoke(array(), array(), array())
This is needed as the program can't know in which document is stored the script.

When you want to call a script exposed from a package location, you need to pass the full path, which is not reflected in the organizer dialog :

Code: Select all

    doc = thiscomponent
    uri = "vnd.sun.star.script:apso.oxt|python|pythonpath|apso_utils.py$console?language=Python&location=user:uno_packages"
    mspf = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
    msp = mspf.createScriptProvider("")
    script = msp.getScript(uri)
    script.invoke(array(), array(), array())
Regards
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
LibreOfficiant
Posts: 12
Joined: Wed Jan 25, 2017 9:36 pm

Re: Unable to call a Python extension macro from Basic

Post by LibreOfficiant »

Hi,

Nice to have you back.
And « many thanks » by the way for solving this issue.

Cordially
libO 5.4 64bit, (PortableApps: libO 6.0, aOO 4.1, OOo 3.2 32bit) on Win7/Win10 x64 | aOO 4.1.x & libO 5.4.x on Mint 18 Sarah & OSX 10.9 Mavericks x64
Python toolbox: Geany, PyCharm and APSO, MRI extensions..
https://wiki.documentfoundation.org/Macros/Design_Guide
Post Reply