Script example: editor integration for CoDeSys components¶
This script solution enables optimization when dealing with different component types that are equally based on CoDeSys but require different project planning environments.
Files required for this script function¶
File name | Description | Functionality |
---|---|---|
ScriptBeforeEdit.exe | Is provided in the script package | Depending on the component type ID, links the project file configurably with an editor |
ScriptBeforeEdit.ini | Can be edited with a text editor | Defines the BeforeEdit script for a specific component type ID |
ScriptBeforeCompare.exe | Is provided in the script package | Configures the comparison process depending on the component type ID the required editor |
ScriptBeforeCompare.ini | Can be edited with a text editor | Defines the BeforeCompare script for a specific component type ID |
Codesys_editor.script | Can be edited with a text editor | Script that is processed by the script interpreter |
The script solutions can be used independently of each other.
Prerequisites for the script solution¶
The respective CoDeSys editors must be accessible locally under a uniform path, i.e. for several computers this local access path must be the same.
Setting up the script¶
Activating ScriptBeforeEdit.exe¶
Copy the application to the Server scripting directory for automatic update of client tab.
Editing ScriptBeforeEdit.ini¶
We recommend that you add any existing ScriptBeforeEdit.ini
file from the Server scripting directory for automatic update of client tab. If this file does not (yet) exist, please use the template from the script package.
- Activate the CoDeSys editor script by entering the connection from the component type ID to the script in the [General] section.
- If several different component types are to be linked to the script, a new entry must be made for each component type ID.
- Save the file.
- Copy the file to the Server scripting directory for automatic update of client tab.
Example:
Concrete example:
Editing Codesys_editor.script 1¶
- Open the
CoDeSys_editor.script
file in the text editor. - Edit the ScriptBeforeEdit script application.
- If necessary, make the adjustments listed in the following table.
- Save the file.
- Copy the file to the Server scripting directory for automatic update of client tab.
Script¶
Function ScriptBeforeEdit
{
// Assign the editors for the Codesys components
// here (component typeId <-> Codesys Editor)
$def::var1 = $func::getifcomponenttypeid(<Component type Id 1>,<Editor 1>)
$def::var1 = $func::getifcomponenttypeid(<Component type Id 2>,<Editor 2>)
$def::var1 = $func::getifcomponenttypeid(<Component type Id 3>,<Editor 3>)
exit.ifemptyvar $def::var1
$def::var2 = $vdog::specific->WorkingDir$vdog::specific->SelectedFile
call $def::var1
{
arg $def::var2
wait 0
rundir $def::var1
}
done
}
Customizations¶
Line 5:
A specific component type ID is assigned to a specific editor here.
$def::var1 is only assigned the definition for the editor path as a value if the component type ID matches that of the job.
The following therefore applies: $def::var1 = If component type ID then use editor.
The script syntax for this is: $def::var1 = $func::getifcomponenttypeid(<Component type Id>
,<Editor>
)
<Component type Id>
must now be replaced with the specific component type ID that is to be linked to a specific editor.
<Editor>
must now be replaced with the absolute path to the editor that is to be linked to the component type ID.
Example: $def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD, C:\Program Files\myeditor.exe)
Lines 6, 7:
These lines can be removed if no further editor assignments are required. The configuration is carried out as in line 5, and further lines may also be inserted for additional editor assignments.
Line 9:
All editor assignments must be made before this line. If the script is called although the component type ID is not (yet) taken into account in the editor assignment, the script is terminated on this line. The standard logic for opening the editor is executed.
Activating ScriptBeforeCompare.exe¶
Copy the application to the Server scripting directory and the Server scripting directory for automatic update of client tabs.
Editing ScriptBeforeCompare.ini¶
We recommend that you add any existing ScriptBeforeCompare.ini
file from the Server scripting directory directory. If this file does not (yet) exist, please use the template from the script package.
Info
The adjustments for ScriptBeforeCompare.ini
must be made twice, once for the configuration in the Server scripting directory tab and once for the configuration in the client scripting directory. Although the configuration files for server and client have the same name, they may have different contents (related to the script configurations for other components).
- Activate the CoDeSys editor script by entering the connection from the component type ID to the script in the [General] section.
- If several different component types are to be linked to the script, a new entry must be made for each component type ID.
Example:
Specific example:
Extending the activation list¶
- The BeforeCompare event takes into account a list of component type IDs for which the script is to be activated (activation list).
- In this list, use the CTIDn keys to list all component type IDs for which the script is to be executed. Add the component type IDs of the CoDeSys components here.
- Save the file.
- Copy the file to the Server scripting directory tab.
Example:
Concrete example:
Editing Codesys_editor.script 2¶
- Open the
CoDeSys_editor.script
file in the text editor. - Edit the ScriptBeforeCompare script application.
- If necessary, make the adjustments listed in the following table.
- Save the file.
- Copy the file to the Server scripting directory for automatic update of client and to the Server scripting directory.
Script 2¶
Function ScriptBeforeCompare
{
// Assign the editors for the Codesys components
// here (ComponenttypId <-> Codesys Editor)
$def::var1 = $func::getifcomponenttypeid(<CoDeSys ComponentTypeId 1>,<Editor for type 1>)
$def::var1 = $func::getifcomponenttypeid(<CoDeSys ComponentTypeId 2>,<Editor for type 2>)
$def::var1 = $func::getifcomponenttypeid(<CoDeSys ComponentTypeId 3>,<Editor for type 3>)
// set the editor
$def::var2 = $vdog::rootdir\VD$A\Configuration\Compare\AgentStation.ini
file.append $def::var2
{
write.ini [CoDeSys]\7220=$def::var1
}
}
Customizations 2¶
Line 5:
A specific component type ID is assigned to a specific editor.
A component type ID is defined as a condition. $def::var1 is only assigned the definition for the editor path as a value if the component type ID matches that of the job.
The following therefore applies: $def::var1 = Condition (Component type ID, editor).
<component type Id>
must now be replaced with the specific component type ID that is to be linked to a specific editor. <Editor>
must now be replaced with the absolute path to the editor that is to be linked to the component type ID.
Example:
$def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD, C:\Program files\myeditor.exe)
Lines 6, 7:
These lines can be removed if no further editor assignments are required. The configuration is carried out as in line 5, and further lines may also be inserted for additional editor assignments.