Customization > Automation Interface > Running Visual Basic Scripts from Modeler > Running Visual Basic scripts from the Modeler tools menu (automation interface)
  
Running Visual Basic scripts from the Modeler tools menu (automation interface)
As an alternative to creating Visual Basic applications that use the automation interface, you can create Visual Basic script files, and then run those files through the Modeler Tools menu. Using Visual Basic scripts files in this way has the following advantages:
If the Visual Basic script changes the Model, those changes are instantly seen without the need to refresh.
You can quickly write Visual Basic script files without having to compile the scripts into a Visual Basic application.
* 
If you run a Visual Basic script from the Modeler Tools menu and that script has errors, those errors can cause Modeler to crash.
For more information about VBScript, see the VBScript user's guide and reference guide on the Microsoft MSDN website. At the time of writing this topic, the button that follows opens the VBScript section of the Microsoft MSDN website.
When you run a Visual Basic script from the Modeler Tools menu, you always have the Modeler object available to you. If you have a Model open in Modeler, you also have the Projects, ActiveProject and Dictionary objects available to you, without needing to create these objects:
The Studio object represents the Modeler editor and can be used to control the user interface. For example, Studio.ClearOutputWindow
The Projects object is the standard Projects object in the automation interface. The Projects object is the collection of Models available in the repositories that are bookmarked in your Model Explorer.
The ActiveProject object is the standard Project object (for the open Model) in the automation interface. The Project object is the container object for the Dictionary and Diagrams collections, that is, the Model.
The Dictionary object is the standard Dictionary object (for the open Model) in the automation interface. The Dictionary object is a container for all dictionary items in the Model.
From the Projects object, you can quickly navigate to the active diagram, selected symbols on a diagram, or selected dictionary items. For more information, click here .
The script can include the following functions.
For validating the use of the script and interacting with the user (for example, opening selection dialogs and displaying messages), use the RunToolUI function.
For making updates to the model, use the CommitTool function
These functions cannot be used in any other scripts.
RunToolUI Script function - This function is called when the script is run.
Use this function to validate the use of the script and interact with users. This function is run outside of the script transaction, so its script should not make any changes to the Model.
Do not use the RunToolUI function to make changes to the model, because the user will have to perform a refresh to see the changes, and the changes cannot be undone.
If the RunToolUI function returns FALSE, the script operation is abandoned.
CommitTool Script function - This function is called after the RunToolUI function has been called.
Use this function to make updates to the model. This function is run as a transaction, so any changes made by the script are immediately seen in Modeler, and the changes can be undone in Modeler.
Do not use the CommitTool function to interact with users, because items in the model will be locked and unavailable to other users while that interaction takes place.
* 
The Dictionary object is not available within a CommitTool function.
If the CommitTool function returns FALSE, the command operation is abandoned.
To run Visual Basic scripts from the Tools menu you require a Modeler license and API Access license.
To add a Visual Basic script to the Tools menu:
1. On the Tools menu, click Customize.
2. Click the Add button.
3. Type the text you want to appear in the Tools menu.
* 
You can specify submenus using backslashes, for example, Editors\Text\Notepad.
4. Press the Enter key.
5. Select the Script check box.
6. Select the Display in Tools Menu check box.
7. Click Browse.
8. Select the Visual Basic script file, and then click Open.
9. If you want the new command to appear in a specific place on the Tools menu, select the command in the list, and then use the arrow buttons to move the command to the required position.
10. If you want the new command to appear on the context menu of specific item and diagram types:
a. Click Advanced.
b. Select the check boxes associated with the required item and diagram types.
c. Click OK.
11. Click OK.