Aug 5, 2022

Executing Python scripts with Arc

Starting with Arc v3.5, Arc can execute Python scripts and retrieve the results. There are two main advantages of using Arc to execute your Python scripts:

  1. Arc handles the credentials to the TM1 instances.
  2. You can display the output from your script in an Arc plugin.

Prerequisites:

  • Python needs to be installed on the server where Arc is running.
  • The Arc server needs to have access to the python.exe file. To find where python is installed, just open a command prompt and enter where python.
  • If you want to use TM1py, you will have to install TM1py on the server as well.

Configuration:

In the Arc settings.yml, you need to add the following setting:

# Python plugincommandpath: .exec

exec is the name of the folder where you need to put the Python files.

# Python plugin

commandpath: .exec

In the root directory of Arc (where arc.exe is) create exec directory.

After running the first script, Arc will create two subdirectories: input and output.

These two subdirectories will be managed by Arc service. Arc will put input and output json files into respective directories. The python scripts to be executed will need to be placed into the exec directory by the admin.

The next step is to create an Arc plugin to execute python scripts. These plugins should be marked for admin only.

Example

Once downloaded, copy the execute-command folder into your plugins folder:

Inside the folder, you will find the python script, test.py:

Move the test.py file into the Arcexec folder created above.

Refresh your browser (clear the cache), you will see find the sample plugin under Tools:

This application takes two parameters Cube name in the TM1 model and name of the script that was placed to the exec directory. After saving and running, Arc will create json files in input and put directories and output results in the browser:

Output from the Python scripts

There are two types of output that can be displayed in Arc:

  • Standard output generated by the print function (in orange above).

  • The Output written into the output file (in blue above).

Related content

Loading related content