Python Code

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Python Code

Post by armsys » Sun Nov 01, 2015 6:23 am

Would anyone be very kind enough to share your complete MS+Python code with us?
Thank you.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Tue Nov 03, 2015 11:26 am

What are you looking for?

There's an example here:
https://www.mjtnet.com/blog/2014/11/07/ ... -recorder/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Tue Nov 03, 2015 11:34 pm

Houston, I have a problem!
MS crashes at Line 37. Please rescue me.
MS13.jpg

Code: Select all

/*
First ensure Python27.dll and imports are in your Macro Scheduler program folder.
Download and unzip this file:
 
https://www.mjtnet.com/software/python27.zip
 
*/
 
Let>url=http://ip.jsontest.com/
 
/*
python_code:
 
import urllib2
import json
 
# grab data from http://ip.jsontest.com/ - see www.jsontest.com
response = urllib2.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 pubic IP is: %myip%

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Wed Nov 04, 2015 9:31 am

You don't say what the error is. But as well as the DLL you need the Imports. This uses urllib2 so you'll need that lib.

"First ensure Python27.dll and imports are in your Macro Scheduler program folder".
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 9:52 am

Marcus Tettmar wrote:You don't say what the error is. But as well as the DLL you need the Imports. This uses urllib2 so you'll need that lib.
Where can I download the urllib2 please?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 10:13 am

The following two files are the best I can find:

Code: Select all

urllib2.py
urllib2.pyc
Please help. Thanks.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 10:38 am

Marcus Tettmar wrote:You don't say what the error is.
When executing Line 37, msched.exe suddenly vanishes from Windows without leaving any traces.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Wed Nov 04, 2015 11:10 am

I think you're trying to make this more complicated - just extract the ENTIRE zip to the Macro Scheduler program folder!

1. Download this file:
https://www.mjtnet.com/software/python27.zip

2. Extract EVERYTHING from that zip into the Macro Scheduler 14 *program folder* (usually c:\program files (x86)\Macro Scheduler 14

3. You should see python27.dll as well as Lib, DLLs, and libs sub folders and these should contains a bunch of files and sub folders.

Now your script should run
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 12:43 pm

Marcus Tettmar wrote:1. Download this file:
https://www.mjtnet.com/software/python27.zip
2. Extract EVERYTHING from that zip into the Macro Scheduler 14 *program folder* (usually c:\program files (x86)\Macro Scheduler 14
3. You should see python27.dll as well as Lib, DLLs, and libs sub folders and these should contains a bunch of files and sub folders.
Now your script should run
Thank you for help. The code does work finally.
The Bible never mentions that all folders & files in python27.zip must be copied to the Macro Scheduler folder.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Wed Nov 04, 2015 1:16 pm

armsys wrote:The Bible never mentions that all folders & files in python27.zip must be copied to the Macro Scheduler folder.
It does. From the PyExec topic in the help file (or online here: https://www.mjtnet.com/manual/index.html?pyexec.htm):
Requires the Python 2.7 DLL to be installed and in the path.

We recommend installing the python27.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 2.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).[/size]
Added emphasis mine.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 1:49 pm

Marcus Tettmar wrote:
Requires the Python 2.7 DLL to be installed and in the path.

We recommend installing the python27.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 2.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).[/size]
Added emphasis mine.
At least, the above description seems to me that only python27.dll would suffice.
Sorry, my misunderstanding.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Wed Nov 04, 2015 1:51 pm

"We've provided a zip file ....... Export the contents "

I'm sorry if that is somehow not clear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Python Code

Post by armsys » Wed Nov 04, 2015 2:53 pm

In order for Python to run under MS, it requires: 3 folders & 1 file installed in C:\Program Files (x86)\Macro Scheduler 14:
DLLs (folder)
Lib (folder)
libs (folder)
python27.dll (file)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python Code

Post by Marcus Tettmar » Wed Nov 04, 2015 3:02 pm

And a whole heap of other files inside those folders.

So just extract the entire contents of the provided zip file to your Macro Scheduler program folder, as per our instructions.

Just unzip the folder there. That's it!!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts