1. Home
  2. Knowledge Base
  3. Octoplant Server
  4. Tutorials
  5. Scripting
  6. ScriptingPackageExamples
  7. KB-127639: Example of a script used for connecting to an editor

KB-127639: Example of a script used for connecting to an editor

Example of a script used for connecting to an editor

This script solution allows optimization in dealing with different component types that equally have a file with a certain extension, but should be opened with a certain editor depending on the component type.

For this purpose, the BeforeEdit script links the project file to an editor in a configurable way depending on the component type ID.

Necessary files for this script function:

File nam Description Functio
ScriptBeforeEdit.exe Available in the scripting package Links the configurable project file with an editor, depending on the Component type ID
ScriptBeforeEdit.ini Can be edited with a text editor Defines the script BeforeEdit for a specific component type ID
Editor_mapping.script Can be edited with a text editor script, which was processed by the script interpreter

Requirements for scripting solutions

  • Recommendation: Install the editors on different computers, so that they are always under the same local access path in the same directory
  • In contrast, if an editor is installed on different computers in different directories then each possible access path needs to be entered into the script and configured there

Set up script

Activate ScriptBeforeEdit.exe

Copy the application into the Server scripting directory for automatic update of client

Edit ScriptBeforeEdit.ini

We recommend that you edit theScriptBeforeEdit.initaken from the Server scripting directory for automatic update of client. If this file is not yet available, use the template from the scripting package.

  1. Activate the mapping script editor by entering the connection to the Component type ID in the section [General]
  2. If more than one different component type is connected to the script, a new entry is required for each component type
  3. Save the file
  4. Copy the file into the Server scripting directory for automatic update of client

Example:

1 2 3

[General] //Component types, connection to the component type ID with an existing editor<ComponentTypeID>= editor_mapping

Specific example:

1 2

[General] 5A527AA2D4A846208BB8648EED1146BD= editor_mapping


Edit the editor_Mapping.script

  1. Open the editor_Mapping.script in the text editor
  2. Edit the function ScriptBeforeEdit.
  3. If necessary, make the adjustments listed in the table below.
  4. Save the file.
  5. Copy the file to the Server script directory for automatic client update.

Script:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

Function ScriptBeforeEdit { //—————————————————- // de: // de: // Script configuration // var1 -> Allocation (Component type ID<-> Editor) // var2 -> Filter, the files that the script should monitor. // var3 -> Format the execution argument to open the file in the editor // // en: // Script-Configuration: // var1 -> Mapping of ComponenttypeId 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

//—————————————————- // de: // Scriptlogic // // en: // Script logic // exit.ifemptyvar $def::var1

continue.ifselectedfilefiltermatch $def::var2

call $def::var1 { arg $def::var3 wait 0 rundir $def::var1 }

done }

Lines Descriptio
17 A specific component type ID is assigned to a specific editor.A component type ID is defined as a condition.$def::var1is assigned the definition to the editor path as a value only exactly when the component type ID matches that of the job.The following applies:$def::var1 = If component type ID matches then use editorScript syntax:$def::var1 = $func::getifcomponenttypeid (<ID n>, <Editor n>)<ID n> needs to be substituted with the exact component type ID with which you wish to link the editor to.<Editor n> needs to be substituted with the absolute path to the editor with which you wish to link the component type ID to.The function $func::getiffileexists(…) takes over the specification only if the editor can also be found locally.Example with test as to whether the editor exists locally:$def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD,$func::getiffileexists(C:Program filesmyeditor.exe)) Example without test as to whether the editor exits:$def::var1 = $func::getifcomponenttypeid(5A527AA2D4A846208BB8648EED1146BD,C:Program filesmyeditor.exe)
18, 1 These lines can be removed if there aren’t any other necessary editors. The configuration occurs just like in line 5.You can add additional lines if there are any other necessary editors.
2 It is possible to configure a file filter in order to determine which files the script should link to the editor.Example:$def::var2 = .txt|.datOnly files with the endings TXT and DAT will be recognized by the script. For all other endings, the script will simply end. The standard logic for opening the editor is executed.Example:$def::var2 =No file is filtered. The script is used for each file.
2 Format the command lines to specify how you want the file in the editor to open. This depends on the respective editor.Example for notepad:$def::var3 = $vdog::specific->WorkingDir$vdog::specific->SelectedFileExample for a different editor:$def::var3 = Projekt:$vdog::specific->WorkingDir$vdog::specific->SelectedFile
3 All editors need to assigned before this line.If the script was executed, even though the specified component type ID was not (yet) included, the script will end exactly at this line. The octoplant system only uses standard logic to open the editor.
3 This is where the configured file filter is checked. If the file matches the filter, the script will continue to run, otherwise the script is aborted at this point and the opening of the editor is performed by the system.

Last update: September 15, 2023

Related Articles

IMPRINT | PRIVACY POLICY | COOKIE POLICY

Privacy Preference Center