Page 1 of 1

Call a Macro Directly From a Python Script?

Posted: Fri Aug 31, 2012 9:28 am
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?

Re: Call a Macro Directly From a Python Script?

Posted: Sat Sep 01, 2012 5:48 pm
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

Re: Call a Macro Directly From a Python Script?

Posted: Sun Sep 02, 2012 1:16 am
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.

Re: Call a Macro Directly From a Python Script?

Posted: Sun Sep 02, 2012 5:38 am
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

Re: Call a Macro Directly From a Python Script?

Posted: Mon Sep 03, 2012 10:58 pm
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.

Re: Call a Macro Directly From a Python Script?

Posted: Sun Sep 09, 2012 8:12 pm
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.

Re: Call a Macro Directly From a Python Script?

Posted: Wed Sep 19, 2012 8:01 pm
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!