Bug 160685 - CreateScriptService("Calc") produces AttributeError: 'NoneType' object has no attribute 'createScriptProvider'
Summary: CreateScriptService("Calc") produces AttributeError: 'NoneType' object has no...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
24.2.2.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2024-04-15 21:42 UTC by latgarf
Modified: 2024-04-16 12:16 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description latgarf 2024-04-15 21:42:06 UTC
The last line of this basic Python script 
inspired by the official doc
https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_calc.html

################################################
import sys

PATH = '/usr/lib/libreoffice/program/'
if PATH not in sys.path:
    sys.path.append(PATH)

from scriptforge import CreateScriptService
doc = CreateScriptService("Calc")
################################################

produces this error:

################################################
Traceback (most recent call last):
  File "/test.py", line 8, in <module>
    doc = CreateScriptService("Calc")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/libreoffice/program/scriptforge.py", line 2992, in CreateScriptService
    ScriptForge()
  File "/usr/lib/libreoffice/program/scriptforge.py", line 73, in __call__
    cls.instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/libreoffice/program/scriptforge.py", line 150, in __init__
    ScriptForge.scriptprovider = self.ScriptProvider(self.componentcontext)  # ...script.provider.XScriptProvider
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/libreoffice/program/scriptforge.py", line 199, in ScriptProvider
    return masterscript.createScriptProvider("")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'createScriptProvider'
################################################

This is my first bug report, sorry if my report is not ideal.
Comment 1 Rafael Lima 2024-04-16 12:16:01 UTC
Are you running this script from within a document?

If so, I recommend you create a function and make it available as a script. To do this, follow the example "Creating Python script files" in the following help page:

https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_intro.html

It would be something like:

from scriptforge import CreateScriptService

# This is your macro
def my_script(args=None):
    doc = CreateScriptService("Calc")
    # Here you can do whatever you want with 'doc'

# Here you make the macro available
g_exportedScripts = (my_script, )

Now you can go to Tools - Macros - Run Macro. Under "My Macros", search the module you've just created (it will be the name of the Python file without the .py), and then you can select 'my_macro' and run it.