You’re right, well spotted. I was just simplifying the name … because it didn’t seem that relevant. The macro name is correct in this script… which fails with the error. Pointing out that something fails is not “going round in circles”. My “direct” method of re-writing content.xml to set up events works. This (in Python, so far) doesn’t.
import uno
from com.sun.star.beans import PropertyValue
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;"
"StarOffice.ComponentContext")
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
dispatcher = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
filepath = r"D:\My Documents\software projects\EclipseWorkspace\lo_base_automation\with_py_macros.odb"
fileUrl = uno.systemPathToFileUrl(os.path.realpath(filepath))
document = desktop.loadComponentFromURL(fileUrl, "_default", 0, ())
form = document.FormDocuments.getByName('test_kernel.invoices')
document.CurrentController.connect()
form_name = 'test_kernel.invoices'
prop1 = PropertyValue(Name='Hidden', Value=True)
# form_doc = document.CurrentController.loadComponentWithArguments(2, form_name, True, prop1)
form_doc = document.CurrentController.loadComponent(2, form_name, True)
prop2 = (PropertyValue(Name='EventType', Value='Script'),
PropertyValue(Name='Script', Value='vnd.sun.star.script:my_2base_script.py$on_load_invoice_form?language=Python&location=document'))
form_doc.Events.replaceByName('OnLoad', prop2)
form.store()
form.dispose()