Script example: general editor link¶
This script solution enables optimization when dealing with different component types that have the same file with a specific extension, but are to be opened with a specific editor depending on the component type.
To do this, the BeforeEdit script links the project file to a configurable editor depending on the component type ID.
Files required for this script function¶
File name | Description | Functionality |
---|---|---|
ScriptBeforeEdit.exe | Is provided in the script package | Links the project file configurably to an editor depending on the component type ID |
ScriptBeforeEdit.ini | Can be edited with a text editor | Defines the BeforeEdit script for a specific component type ID |
Editor_Mapping.script | Can be edited with a text editor | Script that is processed by the script interpreter |
Prerequisites for the script solution¶
- Recommendation: Install the editors on different computers so that they are always under the same local access path in the same folders.
- However, if an editor is also installed in different folders on different computers, every possible access path must be specified and configured in the script.
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 client scripting directory. If this file does not (yet) exist, use the template from the script package.
- Activate the editor mapping 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:
[General]
//Component types, linking the component type ID to a specific editor.
{Component type ID}= editor_mapping
Specific example:
Editing editor_Mapping.script¶
- Open the
editor_Mapping.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
{
//----------------------------------------------------
//
// en:
// Script configuration
// var1 -> Assignment (component type Id <-> editor)
// var2 -> Filter which files should be considered by the Script.
// var3 -> Formatting of the call argument to open the file in the editor
//
// en:
// Script-Configuration:
// var1 -> Mapping of Component type Id to Editor
// var2 -> specification of files which should be treated by this script.
// var3 -> formated argument to launch the selected file in the editor.
//
$def::var1 = $func::getifcomponenttypeid(<Id 1>, $func::getiffileexists(<Editor 1>) )
$def::var1 = $func::getifcomponenttypeid(<Id 2>, $func::getiffileexists(<Editor 2>) )
$def::var1 = $func::getifcomponenttypeid(<Id 3>, $func::getiffileexists(<Editor 3>) )
$def::var2 =<Filefilter specification>
$def::var3 = $vdog::specific->WorkingDir$vdog::specific->SelectedFile
//----------------------------------------------------
// en:
// Script logic
//
// en:
// Script logic
//
exit.ifemptyvar $def::var1
continue.ifselectedfilefiltermatch $def::var2
call $def::var1
{
arg $def::var3
wait 0
rundir $def::var1
}
done
}
Customizations¶
Line 17:
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 = If component type ID matches then use editor.
The script syntax for this is: $def::var1 = $func::getifcomponenttypeid(<ID n>
,<Editor n>
) <ID n>
must now be replaced with the specific component type ID that is to be linked to a specific editor. <Editor n>
must now be replaced with the absolute path to the editor that is to be linked to the component type ID.
The $func::getiffileexists(...) function only accepts the specification if the specified editor can actually be found locally.
Example with check whether the editor exists locally: $def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD,$func::getiffileexists(C:\Program files
myeditor.exe))
Example without checking whether the editor exists: $def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD, C:\Program files\myeditor.exe)
Lines 18, 19: These lines can be removed if no further editor assignments are required. The configuration is carried out as in line 5. Further lines may also be inserted for additional editor assignments.
Line 21:
A file filter can be configured here to determine which files are to be linked to an editor by the script. Example: $def::var2 = .txt|.dat
Only files with the extension TXT or DAT are taken into account by the script. The script is terminated for all other extensions. The standard logic for opening the editor is executed.
Example: $def::var2 =
No file is filtered. The Script is applied to every file.
Line 23:
Formatting of the command line, how the selected file should be opened in the editor. This depends on the respective editor.
Example for Notepad: $def::var3 = $vdog::specific-> WorkingDir$vdog::specific-> SelectedFile.
Example for another editor: $def::var3 = Project:$vdog::specific-> WorkingDir$vdog::specific-> SelectedFile
Line 32:
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 at this line. The standard logic for opening the editor is executed.
Line 34:
The check for the configured file filter takes place here. If the current file matches the filter, the script continues, otherwise the script is aborted at this point and the editor is opened by the system.