Skip to main content

Scripting

The CODESYS scripting engine is extended with functions by CODESYS File-Based Storage which can be used in a script to open a file-based project, to convert a project to the file-based storage format, and to validate a project before conversion. The scripting functionality is available only when the CODESYS File-Based Storage plug-in is installed.

. The scripting engine provides two global objects:
  • fbs: Entry point for file-based storage operations

  • FBSValidationStatus: List of validation states

Opening a project (fbs.open)

Use fbs.open to open a file-based project or a workspace.

Example 2. Example
project = fbs.open(path, primary=True, update_flags=VersionUpdateFlags.NoUpdates, index=-1)


path

Path to the project folder or to a workspace file (.fbsws)

primary

If primary is set to True, then the project will be opened as the primary project.

The default value is True.

update_flags

Version update flags which control whether or not the libraries and compiler version are updated when the project is opened.

The default value is VersionUpdateFlags.NoUpdates.

index

Index of the project to be opened when path is a workspace file with multiple projects.

Return value: The function returns the open project.

Converting a project (convert_to_fbs)

Each project object is extended with the convert_to_fbs method. This method is available only when the CODESYS File-Based Storage add-on is installed.

Example 3. Example
success = project.convert_to_fbs(path, native_import_handler, update_flags=VersionUpdateFlags.NoUpdates)


path

Destination directory for the converted project

native_import_handler

Import handler which is used during the conversion

update_flags

Version update flags which are applied when opening the converted project. The default value is VersionUpdateFlags.NoUpdates.

Return value: When the conversion is successful, True is returned. During the conversion, the source project is closed and a new, empty file-based project is opened as the primary project.

Validating a project (validate_for_fbs)

Use validate_for_fbs to check a project for problems before conversion.

results = project.validate_for_fbs()

When there is no problem, an empty list will be returned. Otherwise, a list of validation results will be returned. Each result has the following properties:

status

Status of the result of type FBSValidationStatus, Warning, or Error

message

Description of the problem

affected_object

Object to which the problem refers