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:\Users\(Your logged in User)\AppData\Local\Programs\Python\Python36
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:\Python36\python.exe.
2. Locate the Python script
The script we want to run is
- C:\TM1py\TM1py-samples-master\Load Data\fx 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:
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:\Python36\python.exe"' ; pyFile = '"C:\TM1py\TM1py-samples-master\Load Data\fx 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. You can check your command line in the command window:
- "C:\Python36\python.exe" "C:\TM1py\TM1py-samples-master\Load Data\fx rates to cube daily.py"
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.