# Running a 2D model in TRIK Studio from PyCharm

{% hint style="info" %}
This article is automatically translated from Russian by Google Translator.
{% endhint %}

This article deals with setting up and using the external programming environment **PyCharm** to call programs in the [2D model ](https://help.trikset.com/en/studio/2d-model)of TRIK Studio.

This will allow experienced TRIK Studio users to use all the features of professional text editors and their plugins: static analyzers, auto formatters, color themes.

It also tells how to automatically run the program on several fields, which can be useful for participants of competitions with automated checking systems.

## **Preparation**

It is assumed that the user is writing a program in an external editor and would like to run this program on one or more fields. Fields can be presented both in the `.xml` format (more details in the article "[2D model tuning](https://help.trikset.com/en/studio/2d-model/settings)"), and in the`.qrs` format.

1. Download [run\_2d\_model.cmd](https://gist.github.com/anastasiia-kornilova/2b955e62c3cef7a509fc043a189ea3ff) file for Windows or  [run\_2d\_model.sh](https://gist.github.com/anastasiia-kornilova/f13a708562debabeeb126381f3d535e5) for Linux and place it in the folder where TRIK Studio is installed.
2. Place the fields on which you want to test the program in a separate folder. If the fields are in `.xml` format, create an empty `default.qrs` project in this folder.

## Setting up PyCharm

{% hint style="danger" %}
Instructions tested on PyCharm Professional Edition (2019.3). \
You can download PyCharm from the [official website](https://www.jetbrains.com/ru-ru/pycharm/).
{% endhint %}

1\. Open the source code folder in **PyCharm** with `File → Open`.

2\. Choose`File → Settings` or press the key combination `«Ctrl+Alt+S»`.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfPT8Z7zweZ72tsOyF%2F43%201%20En%20%20PyCharm_Run_2D%203.png?alt=media\&token=b4f1042d-25a0-4396-8069-6d1d6dfecb3e)

3\. Choose`Tools → External tools` and click on the `«+»`.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfPWtTD6mujwBJwfJo%2F43%202%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=95fa539a-6f9e-4bc3-95fe-fcdf7a2d2647)

4\.  In the `Name` field, enter the desired name of the tool, for example, `«run_2d_model»`. In the `Program` field, type your path to the file `run_2d_model.cmd`. In the `Arguments` type the parameters `$FileDir$` and `$FileName$` or choose`Insert Macros` and select the desired parameters from the list. In the `Working Directory` type`$FileDir$` or choose`Insert Macros` and select the desired parameter. Click the `OK` button.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfPcU3w33TMH1T-u24%2F43%203%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=95df4bdf-be14-44b1-a706-74a7ef4d8d99)

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MA5w3GJb2fbahCFRSNL%2F-MA5xuqTMx5O2SvHl3sg%2F4.png?alt=media\&token=cfd56e47-0458-4c69-903e-d8d161231639)

5\. To run the code, select `Tools→ External tools` and `run_2d_model` (or its name, chosen earlier).

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfQCwmLoVqBFCqNmQ7%2F43%205%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=d6c5def3-8749-4870-9484-49b018d84f0b)

6\. To add "hotkeys" select `File → Settings` or press the key combination `«Ctrl+Alt+S»`. In the menu that appears, select the tab `Keymap` and go to the created `external tool`. Click on `run_2d_model` right mouse button, select `Add Keyboard Shortcut`.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfQLI71dcQIPxv4aj5%2F43%206%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=efc60ef8-a453-435e-a9ab-d53fbf93f71d)

7\. In the window that opens, enter the desired key combination to call the Toolbox and click `«ОК»`.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfQQmOTX9BvFj_dRk7%2F43%207%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=7c9cab30-3234-4451-8cae-edbe2a39ecb3)

8\. Now you just have to press the selected combination (in this case `Shift+B`, but it is possible to choose any other) to run the code.

{% hint style="danger" %}
If an error occurs, select `Settings → Tools → Terminal` and enter your path to the cmd.exe file (`shell path`). Then click `Apply`.
{% endhint %}

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MVfPHZVl1mJhLXis0y-%2F-MVfQbZMCuyhMvNrBAAT%2F43%208%20En%20%20PyCharm_Run_2D%202.png?alt=media\&token=bb2f0185-2dd1-49e5-aa0e-3f5ed4a6d185)
