Welcome to OPAL-RT’s Knowledge Base
OPAL-RT offers a repository of support information for optimal use of its technology.
Please note that OPAL-RT knowledge base is not fully optimized for mobile platforms.
For optimal experience, use a desktop computer.
Reference Number: AA-02087 // Views: 39 // Created: 2022-08-10 08:52:00 // Last Updated: 2023-04-06 17:58:39
RT-LAB Python API Script Example to Create a New Project
In the Python API Help, there is a function mentioned called 'NewProject()' https://opal-rt.atlassian.net/wiki/spaces/PRD/pages/143501302/Examples
However, after using it, there are two files missing:
1- .project file
2- a subfolder .settings with a com.opalrt.rtlab.ui.application.prefs file.
And, because of those two missing files, the project cannot be imported into RT-LAB.
Attached to this article, you will find a complete example how to create an RT-LAB project, with the missing files, so that it is possible to import it in RT-LAB afterwards. This script was made for Python 2.7.
Below is a description of the key parts of that script.
First, define a directory where the resulting zip should be created and the name of the project. In this example, it is C:\Users\username\OneDrive - Opal-RT Technologies\Desktop\temp
Second, define which model is going inside that project. For this example, the classic 'rtdemo1' is being used from the installation directory.
Third, define if there is an extra file that needs to be linked to that project too.
These are the only modifications required to be made to the script before running it.
The script is composed of four functions:
The main script in itself is quite simple:
1- Create a new project using the NewProjectWrapper function
2- AddModelInProject to add the model and the extra file
3- Zip everything to be able to import it in RT-LAB.
The goal of 'dummy_file.txt' is to show how to add a file programmatically, that will be added to the File Tab:
- in the script, the file 'dummy_file.txt' is copied beside the model so that it uses a relative path instead of an absolute path.
- It uses the command <AddExtraFile>, but, with it, it is not possible to set the category using this function (S-Function /
Asynchronous Process / Other - which impacts how the file gets
compiled). The workaround is to write directly in the .llm file.