Running Visual Basic scripts from a script item (automation interface)
As an alternative to creating Visual Basic applications that use the automation interface, you can create Script items that are set up as utilities. When you right-click these Script items, and then click Run, the Script item's Visual Basic script is run. Using Visual Basic scripts files in this way has the following advantages:
If the script changes the Model, those changes are instantly seen without the need to refresh. You can quickly write script files without having to compile the scripts into a Visual Basic application.
|
If you run a Visual Basic script from a Script item and the 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 a Script item, 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 that 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, see the Automation Interface Help.
|
A Utility script can include the following functions. All script must be within one or more of the following functions:
• For validating the use of the Utility Script and interacting with the user (for example, opening selection dialogs and displaying messages), use the RunUtilityUI function.
• For making updates to the model, use the CommitUtility function.
These functions cannot be used in any other scripts.
• RunUtilityUI Script function - This function is called when the associated Utility Script is run.
Use this function to validate the use of the Utility Script and interact with users. This function is run outside of the Utility Script transaction, so its script should not make any changes to the Model.
|
Do not use the RunUtilityUI 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 RunUtilityUI function returns FALSE, the Utility Script operation is abandoned.
• CommitUtility Script function - This function is called after the RunUtilityUI 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.
|
Do not use the CommitUtility function to interact with users, because items in the model will be locked and unavailable to other users while that interaction takes place.
|
If the CommitUtility function returns FALSE, the command operation is abandoned.
To run Visual Basic scripts from Modeler you require a Modeler license and an API Access license.
To set up a script item as a utility:
1. Right-click the Model or Package in which you want to create the script, and select > > > .
2. Type a name for the Script, and then press the Enter key.
3. Open the Script's Property Pages, and then click the Settings tab.
4. In the Script Type list, ensure that Utility is selected.
5. Click the Script tab.
6. In the box, type the script.
7. If you want to change the text in a larger window with the Text ribbon tab available, click the Editor button.
8. For more information about working with scripts, see Scripts.
To run the script of a utility script item from Modeler
Right-click the Script item and then click Run.