This chapter shows how to create a new project with the Schneider Electric Script Engine.
Even though there are 4 different project types available, the code for creating them is identical. In these 4 cases, the create_project method of the global object new_project is called.
This instantiates 2 data containers that consist of the following elements:
common project settings
controller settings
The common project settings consist of the following elements:
machine name
author
customer
description
picture (the path to an image)
project name (the name of the project including the file extension .project)
project type
The project type property allows you to select one of the 3 project types:
Property Value |
Description |
---|---|
|
standard project |
|
library |
|
empty project |
The controller settings consist of the following elements
Element |
Description |
---|---|
type |
type of the controller, can be retrieved from the device identification of the controller |
id |
ID of the controller, can be retrieved from the device identification of the controller |
version |
firmware version |
device_name |
name of the device that you can assign |
implementation_language |
6 implementation languages are available |
To create a standard project, the create_project method is called. It consists of the data containers CommonProjectSettings and ControllerSettings.
# Clean up any open project
if projects.primary:
projects.primary.close()
# Create a new instance of the common project settings object
common_settings_DTO = new_project.create_common_project_settings()
common_settings_DTO.machine_name = "Machine Name"
common_settings_DTO.author = "Author"
common_settings_DTO.customer = "Customer"
common_settings_DTO.description = "Description"
common_settings_DTO.picture = None
common_settings_DTO.project_name = "Example.project"
common_settings_DTO.project_path = r"D:\PythonProjects"
common_settings_DTO.project_type = ProjectType.StandardProject
# Create a new instance of the controller settings object
controller_settings_DTO = new_project.create_controller_settings()
controller_settings_DTO.type = 4096
controller_settings_DTO.id = "1003 0082"
controller_settings_DTO.version = "1.53.5.4"
controller_settings_DTO.device_name = "LMC_PacDrive"
controller_settings_DTO.implementation_language = ImplementationLanguage.structured_text
# Create new standard project
new_project.create_project(common_settings_DTO, controller_settings_DTO)
# Save the project
projects.primary.save()