Each Scriptlet has access to three global objects in addition to the standard automation environment. They are:
- theDiagram - an automation Diagram interface to the diagram on which the Scriptlet resides
- theElement - an automation Element interface to the Scriptlet artifact itself
- theInstance - an automation DiagramObject interface to the Scriptlet artifact itself
For references to Help topics related to these objects see the Learn More links.
Scriptlets can be placed on any diagram. You can place any number of Scriptlets on a diagram and you can place a given Scriptlet on more than one diagram.
Construction > Scriplets
To create a Scriptlet:
Code in Scriptlets cannot alter or update elements in the model database. It can, however, read and update copies of the elements that are displayed on a diagram. Updates to elements made by Scriptlets are NOT written back into the model database.
Editing Scriptlet Code
An Example of a ScriptletThis example comes from the model pattern 'Scriptlets > Simple', available through the Model Wizard ( ).
//--- Example Scriptlet ---
var object as EA.DiagramObject;
object = theDiagram.GetObjectByGrid("A","2");
Session.Output("Scriptlet1 for " + theDiagram.Name);
object.BackgroundColor = parseInt("0x554444",16);
object.FontColor = parseInt("0xeeeeee",16);
Running a Scriptlet
Scriptlets are run whenever the diagram containing them is loaded or reloaded, prior to the diagram being displayed. If a diagram contains multiple Scriptlets, the order in which they are run is determined by the Z-order of the Scriptlets on the diagram. Scriptlets can also be run manually at any time, by right-clicking on the Scriptlet and choosing the option 'Run Script' from the context menu.
Debugging a Scriptlet
You can debug a Scriplet as for any other section of code. Right-click on the Scriptlet and select the 'Debug Script' menu option. The Scriptlet is displayed in the Debug View.
Scriptlets on Grid Style Diagrams
The automation API has some specialized functions that Scriptlets can use when acting on diagrams displayed in a Grid style. When a diagram is viewed as a grid, we can use automation functions to retrieve elements at specified grid locations. The location format is the same as one sees in a spreadsheet, with columns labeled 'A', 'B', 'C', ..., 'AA', 'AB', etc. and the rows numbered in sequence.
To alter the appearance of a grid element, retrieve its underlying Object, using the function GetObjectByGrid.
To alter the value of a grid element, retrieve its underlying Element, using the function GetElementByGrid.
object = theDiagram.GetObjectByGrid("A", "2");
element = theDiagram.GetElementByGrid("A", "2");