Call function of another kodi addon
#1
Hi,

so at the moment I have to addons. One service addon (flask webservice) and a programm addon. Now I want to call a function of my programm addon via the service addon.
I found this thread stackoverflow. But I can't change it for my project.
Have someone implemented sth. like this?

Thanks.
Reply
#2
That Stack Overflow description is if you want to import a function from another add-on, which is certainly an option, although I've never tried that.  The other option is to have your service add-on actually call the script with some parameters that would tell it to run and what chunk of your other add-on to run.  You can use xbmc.executebuiltin to run a RunScript command something like this:


scripttorun = "RunScript(script.addon, function)"
xbmc.executebuiltin(scripttorun)

You'd have to build some logic into the receiving addon to parse that arg and figure out what to run. The information on the argument you pass is in sys.argv.

You can also pass a bunch of parameters, and as before, you responsible for parsing them in the receiving add-on:


scripttorun = "RunScript(script.addon, foo=bar&another=thing)"
xbmc.executebuiltin(scripttorun)

The only thing to mention here is that you can't pass any data back to your service add-on with this strategy.  OK, you can, but you'd have to use window properties to do it. So it isn't the most straightforward thing.
Reply
#3
(2021-05-09, 20:59)pkscout Wrote: That Stack Overflow description is if you want to import a function from another add-on, which is certainly an option, although I've never tried that.  The other option is to have your service add-on actually call the script with some parameters that would tell it to run and what chunk of your other add-on to run.  You can use xbmc.executebuiltin to run a RunScript command something like this:


scripttorun = "RunScript(script.addon, function)"
xbmc.executebuiltin(scripttorun)

You'd have to build some logic into the receiving addon to parse that arg and figure out what to run. The information on the argument you pass is in sys.argv.

You can also pass a bunch of parameters, and as before, you responsible for parsing them in the receiving add-on:


scripttorun = "RunScript(script.addon, foo=bar&another=thing)"
xbmc.executebuiltin(scripttorun)

The only thing to mention here is that you can't pass any data back to your service add-on with this strategy.  OK, you can, but you'd have to use window properties to do it. So it isn't the most straightforward thing.

Hi, thanks. But unfortunately I need to get the response of my function to interact with the addon after running.
Nevertheless do you have an example for me to implement RunScript and how to parse it in the receiving addon?

What I have tried:
       
arg1=1
arg2=2
scripttorun = "RunScript(storage/.kodi/addons/plugin1/addon.py, arg1 arg2)"
xbmc.executebuiltin(scripttorun, True)

In the addon.py I have tried the following:

if len(sys.argv) is None:
    myfunction()
else:
    myfunction(sys.argv[0],sys.argv[1])
Reply
#4
(2021-05-11, 21:44)M4tRiX Wrote:
(2021-05-09, 20:59)pkscout Wrote: That Stack Overflow description is if you want to import a function from another add-on, which is certainly an option, although I've never tried that.  The other option is to have your service add-on actually call the script with some parameters that would tell it to run and what chunk of your other add-on to run.  You can use xbmc.executebuiltin to run a RunScript command something like this:


scripttorun = "RunScript(script.addon, function)"
xbmc.executebuiltin(scripttorun)

You'd have to build some logic into the receiving addon to parse that arg and figure out what to run. The information on the argument you pass is in sys.argv.

You can also pass a bunch of parameters, and as before, you responsible for parsing them in the receiving add-on:


scripttorun = "RunScript(script.addon, foo=bar&another=thing)"
xbmc.executebuiltin(scripttorun)

The only thing to mention here is that you can't pass any data back to your service add-on with this strategy.  OK, you can, but you'd have to use window properties to do it. So it isn't the most straightforward thing.

Hi, thanks. But unfortunately I need to get the response of my function to interact with the addon after running.
Nevertheless do you have an example for me to implement RunScript and how to parse it in the receiving addon?

What I have tried:
       
arg1=1
arg2=2
scripttorun = "RunScript(storage/.kodi/addons/plugin1/addon.py, arg1 arg2)"
xbmc.executebuiltin(scripttorun, True)

In the addon.py I have tried the following:

if len(sys.argv) is None:
    myfunction()
else:
    myfunction(sys.argv[0],sys.argv[1])

Check out Artist Slideshow (it’s one of mine). I’m not in front of my computer, so I can’t point you to where, but do a search for sys.argv and the parsing code should be near there.
Reply



Logout Mark Read Team Forum Stats Members Help
Call function of another kodi addon0
This forum uses Lukasz Tkacz MyBB addons.