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.

Call a Macro Directly From a Python Script?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
SDeGonge
Posts: 10
Joined: Thu Aug 09, 2012 10:01 pm

Call a Macro Directly From a Python Script?

Post by SDeGonge »

I'm not sure if this can be done (searched the forum but couldn't find an answer). I would like to execute an eventghost macro from a Python script. Currently I'm raising an event with python which triggers my macro.

eg.TriggerEvent("SetSageExclusive", payload=None, prefix="Call", source=eg)

Is there a way to just call the macro directly similar to a Jump via Python?
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: Call a Macro Directly From a Python Script?

Post by jonib »

SDeGonge wrote:Is there a way to just call the macro directly similar to a Jump via Python?
You can use the Jump action from Python.

I just posted this in an other thread should work for you.
If you need a pointer to a macro just create for example a Jump action to the macro, then copy that action from EventGhosts config tree and paste to a text document. now you see the syntax for the Jump action, including a number to access the specific macro that you can store in a variable.
jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
SDeGonge
Posts: 10
Joined: Thu Aug 09, 2012 10:01 pm

Re: Call a Macro Directly From a Python Script?

Post by SDeGonge »

jonib wrote:
SDeGonge wrote:Is there a way to just call the macro directly similar to a Jump via Python?
You can use the Jump action from Python.

I just posted this in an other thread should work for you.
If you need a pointer to a macro just create for example a Jump action to the macro, then copy that action from EventGhosts config tree and paste to a text document. now you see the syntax for the Jump action, including a number to access the specific macro that you can store in a variable.
jonib
Thanks for the tip. That copy/paste trick is pretty cool, however, I still don't know how to go from this to the proper python syntax. Forgive me - I just got started with eventghost and python so I'm still struggling to do the simplest things.
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: Call a Macro Directly From a Python Script?

Post by jonib »

Unfortunately I missed two things. You need to add a eg.plugins. before the action when run from python.
So eg.plugins.EventGhost.NewJumpIf should work when run from the Python command.
The second thing I missed is the XmlIdLink(1857) part unfortunately I can't figure out what needs to be done to make it work in a Python script.

So my solution is only a partial one, sorry.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
SDeGonge
Posts: 10
Joined: Thu Aug 09, 2012 10:01 pm

Re: Call a Macro Directly From a Python Script?

Post by SDeGonge »

jonib wrote:Unfortunately I missed two things. You need to add a eg.plugins. before the action when run from python.
So eg.plugins.EventGhost.NewJumpIf should work when run from the Python command.
The second thing I missed is the XmlIdLink(1857) part unfortunately I can't figure out what needs to be done to make it work in a Python script.

So my solution is only a partial one, sorry.

jonib
Did some searching and couldn't find anything to help with this problem. Thanks anyway for your quick response.
User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: Call a Macro Directly From a Python Script?

Post by Livin »

maybe this would work, as an alternative... set a global variable in the script, have the Macro trigger based on the variable value.
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system
gechu
Experienced User
Posts: 58
Joined: Sat Jan 07, 2012 10:35 am

Re: Call a Macro Directly From a Python Script?

Post by gechu »

I don┬┤t know much about Python. Here are some WILD guesses: if you look in this file: \EventGhost_0.4.1.r1568_Source\eg\Classes\ActionItem.py, you can find:

Code: Select all

def SetArgumentString(self, argString):
        try:
            args = eval(
                'returnArgs(%s)' % argString,
                eg.globals.__dict__,
                dict(
                    returnArgs=lambda *x: x,
                    XmlIdLink=lambda id: TreeLink.CreateFromArgument(self, id),
                ....


My take is that "XmlIdLink" is defined as some kind of anonymous function related to TreeLink.CreateFromArgument(self, id). Problem is that the first parameter ("self") is a pointer to an instance of an object. And I don┬┤t know where to find that object, or which value I can replace it with.


So my last guess is that XmlIdLink(some number) could be replaced with: eg.plugins.EventGhost.NewJumpIf(eg.Classes.TreeLink.TreeLink.CreateFromArgument(some object, 2541), 2, False)

Please don┬┤t forget that this is WILD WILD guesses!
Post Reply