Customization > Extensibility Through Profiles, Stereotypes, Tag Definitions and Scripts > Script functions, objects and attributes > Script functions, objects and attributes > Script functions, attributes and objects - menu command scripts
  
Script functions, attributes and objects - menu command scripts
In addition to the standard Modeler automation interface functions, objects and attributes, there are special functions, objects and attributes you can use in the scripts of Stereotypes and Script items. For general information about extensibility scripts, including information about the Modeler, Projects, ActiveProject and Dictionary objects that are available in most script functions, see Script functions, attributes and objects - overview.
To write scripts you require a good working knowledge of the VBScript language, the Modeler Meta Model and the Modeler Automation Interface.
* 
If you run a script that has errors, those errors can cause Modeler to crash and corrupt Modeler model data.
A Menu Command script can include the following functions for adding a command to the Modeler user interface. All script must be within one or more of the following functions.
For validating the use of the command and interacting with the user (for example, opening selection dialogs and displaying messages), use the RunMenuUI function.
For making updates to the model, use the CommitMenu function.
For triggering the user interface after making updates through the CommitMenu function, use the AfterMenuCommit function.
For example, you can use the AfterMenuCommit function to display a message, or open a diagram that has been created through the CommitMenu function.
To open a topic that has a script template for menu command scripts, see Script template for menu command scripts. The script template includes the preceding functions (empty).
These functions are case sensitive and cannot be used in any other scripts.
RunMenuUI Script function - This function is called when the associated command is clicked in Modeler.
Use this function to validate the use of the command and interact with users. This function is run outside of the Menu Command script transaction, so its script should not make any changes to the Model.
* 
Do not use the RunMenuUI 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.
This function can use the following object and script attributes:
CurrentObject object - is the item that is right-clicked to call the menu command.
Script.CurrentSymbol script object - is the diagram symbol that is right-clicked to call the menu command. This script object is populated only when a diagram symbol is right-clicked. Example code:
if script.CurrentSymbol is Nothing then
msgbox "No current Symbol"
else
msgbox script.CurrentSymbol
end if
RunMenuUI = False
If the RunMenuUI function returns FALSE, the command operation is abandoned.
CommitMenu Script function - This function is called after the RunMenuUI 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 CommitMenu function to interact with users, because items in the model will be locked and unavailable to other users while that interaction takes place.
This function can use the following object and script attributes:
CurrentObject object - is the item that is right-clicked to call the menu command. Example code:
If (CurrentObject("Class Name") = "Package") Then
Set objNewItem = CurrentObject.Add("Scoped Package")
Else
Set objNewItem = CurrentObject.Item("Dictionary").Add("Package")
End If
Script.CurrentSymbol script object - is the item diagram symbol that is right-clicked to call the menu command. This script object is populated only when a diagram symbol is right-clicked.
If the CommitMenu function returns FALSE, the command operation is abandoned.
AfterMenuCommit Script function - This function is called after the CommitMenu function has been called. You can do this as a sub or function as it does not return a value.
Use this function to trigger the user interface after the CommitMenu function has updated the model. This function is run outside of the Menu Command script transaction, so its script should not make any changes to the Model.
This function can use the following object and script attributes:
CurrentObject object - is the item that is right-clicked to call the menu command. Example code:
If (CurrentObject("Class Name") = "Package") Then
Set objNewItem = CurrentObject.Add("Scoped Package")
Else
Set objNewItem = CurrentObject.Item("Dictionary").Add("Package")
End If
Script.CurrentSymbol script object - is the item diagram symbol that is right-clicked to call the menu command. This script object is populated only when a diagram symbol is right-clicked.