Customization > Extensibility Through Profiles, Stereotypes, Tag Definitions and Scripts > Script functions, objects and attributes > Script functions, objects and attributes > Script functions, attributes and objects - on drop scripts for items
  
Script functions, attributes and objects - on drop scripts for items
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.
The objects and attributes you can use in an On Drop script depends on whether the script is for a diagram or item:
For a diagram, the script is called when a drag-and-drop operation or a copy-and-paste operation is performed on the associated diagram in the diagram editor.
For an item, the script is called when an item is copied or moved to the associated item in a pane.
For Items
An On Drop script can include the following functions for changing the on drop behavior of a diagram (including link reconnections) or item. All script must be within one or more of the following functions.
For validating the drop and interacting with the user (for example, opening selection dialogs and displaying messages), use the ValidDrop function.
For making updates to the model, use the OnDrop function.
To open a topic that has a script template for on drop scripts for items, click here Script functions, attributes and objects - on drop scripts for items. The script template includes the preceding functions (empty).
Note that you cannot share values of variables between the ValidDrop and OnDrop functions.
These functions are case sensitive and cannot be used in any other scripts.
ValidDrop Script function - for an associated item, this function is called when an item is copied or moved to the item in a pane.
Use this function to validate the drag-and-drop operation. This function is run outside of the On Drop script transaction, so its script should not make any changes to the Model.
* 
Do not use the ValidDrop 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 objects and attributes:
Script.DropEffect script attribute that determines which mouse pointer is shown:
Example code:
x = script.DropEffect
If x = 1 then
MsgBox "Copy"
Else
MsgBox "Move"
End If
DropEffect is set to 1 when an item is being copied.
DropEffect is set to 2 when an item is being moved.
DropEffect is set to 4 when a type is assigned to an item through a drag and drop operation within a pane. For example, dragging a Class to an Attribute.
DroppedItem object - is the item that is dragged.
Example code:
if DroppedItem("ClassName")="Attribute" or DroppedItem("ClassName")="Role"
then
if not DroppedItem.item("stereotype","OperationalNode") is nothing then
DropResult("Anonymous")="TRUE"
end if
end if
HitItem object - is the item on which the dragged item is dropped.
If the ValidDrop function returns FALSE, the operation is abandoned.
OnDrop Script function - This function is called after the ValidDrop 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 OnDrop 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:
Script.DropEffect script attribute that determines which mouse pointer is shown:
Example code:
x = script.DropEffect
If x = 1 then
MsgBox "Copy"
Else
MsgBox "Move"
End If
DropEffect is set to 1 when an item is being copied.
DropEffect is set to 2 when an item is being moved.
DropEffect is set to 4 when a type is assigned to an item through a drag and drop operation within a pane. For example, dragging a Class to an Attribute.
DroppedItem object - is the item that is dragged. .
Example code:
if DroppedItem("ClassName")="Attribute" or DroppedItem("ClassName")="Role"
then
if not DroppedItem.item("stereotype","OperationalNode") is nothing then
DropResult("Anonymous")="TRUE"
end if
end if
DropResult object - is the item that is created from the drop.
Example code:
if DroppedItem("ClassName")="Attribute" or DroppedItem("ClassName")="Role"
then
if not DroppedItem.item("stereotype","OperationalNode") is nothing then
DropResult("Anonymous")="TRUE"
end if
end if
HitItem object - is the item on which the dragged item is dropped.
* 
The Dictionary object is not available within an OnDrop function.
If the OnDrop function returns FALSE, the operation is abandoned.