Nov 4, 2017
Run TM1py script from TM1 process
This article explains the steps to run a TM1py script from TM1 process.
1. Locate python.exe
First you need to locate python.exe file. The first locations to look at are:
C:Python36
C:Users(Your logged in User)AppDataLocalProgramsPythonPython36
If you can’t find your python.exe location, you can just type in a command line:
where python
In this example python.exe is located in C:Python36python.exe.
2. Locate the Python script
The script we want to run is
C:TM1pyTM1py-samples-masterLoad Datafx rates to cube.py
3. Create TM1 process
To run a python script from a TM1 process, we are going to use the ExecuteCommand function of the TM1process:
ExecuteCommand(CommandLine, Wait);
The ExecuteCommand function has two parameters:
CommandLine will be the path of the python.exe and the script.
Set Wait to 1 if you want the TM1 process to wait for the script to finish Wait to 0, if you want the process to go straight to the next line.
Create a new TM1 process and add the following code:
pyExe = '"C:Python36python.exe"' ;pyFile = '"C:TM1pyTM1py-samples-masterLoad Datafx rates to cube daily.py"' ;EXECUTECOMMAND(pyExe |' '| pyFile,1);
Because there are spaces in the script name, we need to add double quotes “” inside the single quotes.
Save the process and run it.
If there is an error in the command line, you won’t be able to see it from the TM1 process. Even if the TM1 process runs successfully, the command line could fail.
Things to check if nothing happens:
1. Check your command line in the command window:
“C:Python36python.exe” “C:TM1pyTM1py-samples-masterLoad Datafx rates to cube daily.py”
2. Check if TM1 can access the Python folder to run the python.exe file. (You might need to update the security access of the user running the TM1 service).
3. Check if Python is installed for all users.
If you are planning to run multiple scripts, it is a good practice to store the file locations in a TM1 cube, so you can easily update the file locations if you need to.
You can access the code of the script used in this example, fx rates to cube daily.py on Github.