PyExec
PyExec>Code,OutputBuffer[,var1,var1,....varn]
Executes the specified python code.
OutputBuffer returns any content written to standard IO. Optionally specify one or more Python variables to be extracted using.
Requires the Python 3.7 DLL to be installed and in the path.
We recommend installing the python37.dll in the same folder as Macro Scheduler or of your compiled macro. Any libraries and runtimes can also be included in lib,libs,dll etc folders at the same level, consistent with the usual Python setup.
We've provided a zip file containing the Python 3.7 runtime environment which you can download from here. Export the contents to the Macro Scheduler program folder, or the folder of a compiled macro (.exe).
Important: Only one Python engine can be active at any one time. This means that scripts running simultaneously cannot use PyExec at the same time. Therefore if PyExec is already running in another script your script will wait until the other script has finished with it before continuing. This does not apply to compiled macros running as .exes as these are running as completely separate processes.
If you are using an earlier version of Macro Scheduler with the Python2.7 dll and need backward compatibility you can set the PYTHON_DLL variable to python27.dll:
Let>PYTHON_DLL=python27.dll
Example
Let>url=http://ip.jsontest.com/
/*
python_code:
import urllib.request
import json
import sys
# grab data from http://ip.jsontest.com/ - see www.jsontest.com
response = urllib.request.urlopen('%url%')
# load the json
dict = json.loads(response.read())
# get the ip member
myip = dict["ip"]
# make a nice string representation of the dict
sdict = json.dumps(dict)
# Anything we print to IO is returned in the PYExec output var
print("All Done")
*/
//Load the Python code to a variable
LabelToVar>python_code,pcode
//Run the code and request the values of the sdict and myip variables ...
PYExec>pcode,output,sdict,myip
//Display the IP address
MessageModal>Your public IP is: %myip%