(LO 7.4.6, OS W10)
Just taking first steps with automating Base using Python macros. To get this to work I started with this tutorial page.
This macro works and prints out interesting info on the objects here.
def Explore(*args):
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
form_docs = model.getFormDocuments()
# form_docs turns out to be iterable. There is one form.
# time.sleep(1)
# form_docs[0].open()
# time.sleep(1)
output_file_path_str = r'D:\My Documents\temp\output.txt'
with open(output_file_path_str, 'a') as f:
f.write(f"""
now {datetime.datetime.now()}
form_docs {form_docs} type {type(form_docs)}
dir(form_docs) {dir(form_docs)}
""")
return None
When I uncomment those lines around form_docs[0], I get a âWrappedTargetExceptionâ.
vnd.sun.star.tdoc:/3027442269224/Scripts/python/my_base_script.py (<class âooo_script_framework.com.sun.star.lang.WrappedTargetExceptionâ>:
File âD:\apps\LibreOffice\LibreOffice_7.4.6\program\pythonscript.pyâ, line 915, in invoke
ret = self.func( *args )
NB I know that form_docs[0] has this method open(), because I also did an print out on it, its type and its dir, so it turns out that one of its base classes is XSubDocument where the method open() is documented. It also explicitly says that this method can raise a WrappedTargetException, âif an error occurs during opening the documentâ. Thatâs quite a âgeneralâ explanation
âŠ
Any idea what Iâm doing wrong? Opening a form inside an .odb file might be thought to be a fairly ordinary thing to want to do.
later
- Once⊠it opened the form. Out of maybe 30 runs.
- I tried putting the command in an independent thread⊠no good
- I am puzzled by the API info for WrappedTargetException: I have printed out the following in the
exceptblock:
f.write(f'e {e} type {type(e)}\ndir {dir(e)}\ndir(e.__class__) {dir(e.__class__)}\nstack_trace {stack_trace}\n')
⊠there is no sign of TargetException, Message or Context (or getters for these) in dir(e), output:
now 2023-04-21 08:42:09.722323e type <class 'ooo_script_framework.com.sun.star.lang.WrappedTargetException'>
dir ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__pyunointerface__', '__pyunostruct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__',
'__str__', '__subclasshook__', '__suppress_context__', '__traceback__', '__weakref__', 'args', 'typeName', 'value', 'with_traceback']
dir(e.__class__) ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__pyunointerface__',
'__pyunostruct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__',
'__str__', '__subclasshook__', '__suppress_context__', '__traceback__', '__weakref__', 'args',
'typeName', 'with_traceback']