I like to use Python Scripts and wanted to build out functions (macros with python, jumps and actions) that I could use through out my other macros python scripts with returning values. I do this with plugins but that is all python and I have some macros that are a mixed type of actions.
EX. I have a channel name to channel number function that I copy and paste into my python scripts as needed but would like to centralize it.
Please let me know you thoughts.
Thanks, B
Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Macros as a Function?
Re: Macros as a Function?
Hello m19brandon,
there is no possibility to call a macro directly except the "Jump" action (as far as I know), anyway, I wouldn't recommend to use it inside of scripts.
What you can do is create functions in the eg.globals namespace and call them in your script.
To do that you would need a script that runes at statup that contains and registers your function (this script needs to be executed in order to work):
you can now call eg.globals.testFunction() in any of your scripts and it will print "This is a test!"
there is no possibility to call a macro directly except the "Jump" action (as far as I know), anyway, I wouldn't recommend to use it inside of scripts.
What you can do is create functions in the eg.globals namespace and call them in your script.
To do that you would need a script that runes at statup that contains and registers your function (this script needs to be executed in order to work):
Code: Select all
def test():
print "This is a test!"
eg.globals.testFunction=test-
m19brandon
- Experienced User
- Posts: 177
- Joined: Mon Feb 03, 2014 10:36 pm
Re: Macros as a Function?
That would work. Thanks, B
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Macros as a Function?
There is also a possibility to trigger actions directly from scripts. I have used this method myself. One important thing is that you need to have unique names on actions you wanna trigger this way. And of course, if you add a new action it will not be available until you run the script again.
Example code below
Run this script at EG startup to create a global dictionary available to other scripts
Then trigger actions from scripts like this:
Example code below
Run this script at EG startup to create a global dictionary available to other scripts
Code: Select all
myActions = {}
myConfig = eg.document.__dict__['root'].childs
for i in myConfig:
e = i.GetAllItems()
for j in e:
s = str(j.GetTypeName)
if s.find('ActionItem') > 0:
myActions[j.GetLabel()] = j
#Make the dictionary globally available
eg.globals.myActions = myActions
Code: Select all
eg.globals.myActions['Action name'].Execute()
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
