## Creating Custom ScriptUtil

### 1. Introduction

In case of the existing ScriptUtil APIs cannot meet your requirement, you can create your own ScriptUtil from Java in Eclipse by yourself, and then call your custom ScriptUtil from BOY script. The code of this example is availabe in BOY Examples->Miscellaneous->CustomScriptUtil.

### 2. A Step-by-Step Example

This example will create a simple ScriptUtil that popup a "Hello World!" dialog.

#### 2.1 Pre-requirements

The widget plugin will need to have BOY plugin (org.csstudio.opibuilder) as dependecy, so you need to have BOY plugin and its dependent CSS plugins installed in your Eclipse environment. You can simply copy BOY plugin and its dependencies from your CSS plugin folder to your Eclipse `dropin` folder. If you are a CSS developer, you just need to import these plugins into your workspace from your Mercurial repository.

#### 2.2 Creating a new Fragment

Create a new fragment project with all the default settings. Use plugin `org.csstudio.opibuilder` as host.

#### 2.3 Creating your custom Script Util class

In Fragment src folder, creat a package, for example "org.csstudio.opibuilder.customScriptUtilExample". Go to MATNIFEST.MF->Runtime page, export this package. In this package create a Class and static methods which you will call in BOY script. For example:

    public class MyScriptUtil {

    	public static void helloWorld(){
    		ConsoleUtil.writeInfo("Hello World!");
    		MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Hello",
    				"MyScriptUtil says: Hello World!");
    	}

    }

#### 2.4 Integrate your ScriptUtil into CSS

If you are a CSS developer, now your have finished the fragment project. You can integrate it into CSS by including this fragment into your CSS build. Here we will discuss how to add this fragment to an existing CSS. Open the MANIFEST.MF file and go to the overview tab. Click Export Wizard. Change the Destination Directory to the any directory you want. Leave other settings as default and click Finish. When exporting finished, go to the directory you set and copy the .jar file to CSS `dropins` folder.

### 3. Call your Custom ScriptUtil from BOY script

Here is the JavaScript example. You can also call it from Python Script.

    importPackage(Packages.org.csstudio.opibuilder.customScriptUtilExample);

    MyScriptUtil.helloWorld();