Prev | Next |
Write Scripts
To create an alternative representation for an element or connector, you write a Shape Script that defines the size, shape, orientation and color of the representation. A Shape Script contains a number of sections for defining different aspects of the shape; for an element these include:
- Main object
- Labels
- Decoration (for example, a Document element might contain an icon depicting a document)
For a connector the sections include:
- Main object
- Shape Source
- Shape Target
- Labels
Shape Scripts operate on the basis that the default (UML) representation is used unless the script contains an alternative definition. That is:
- If you have a Shape Script containing just a decoration, this decoration is added on top of the normally-drawn object
- If you have an empty shape routine, it overrides the default; so, a blank 'shape label' prevents the creation of the normal floating text label for elements that have them
You can also comment your scripts using C-style comments; for example:
// C Style Single Line comment
/* Multi Line
comment supported */
Scripting is not case-sensitive: 'Shape' is the same as 'shape'.
Script Structure
Layout |
Description |
See also |
---|---|---|
Example of Element Script Layout |
shape main { // draw the object } shape label { // draw a floating text label } decoration <identifier> { // draw a 16x16 decoration inside the object } The < identifier > string is an alphanumeric word. |
|
Example of Connector Script Layout |
shape main { // draw the line } shape target { // draw the shape at the target end } shape source { // draw the shape at the source end } label <positionLabel> { // define the text for the label } The <positionLabel> string can be any of:
|
|
Sub-shapes |
A shape can have Sub-shapes, which must be declared after the main Shape Script, but called from the Method commands. This is an example of the ordering for declarations: shape main { // Initialisation Attributes - these must be before drawing commands noshadow = "true"; h_align = "center"; //drawing commands (Methods) rectangle (0,0,100,100); println ("foo bar"); // call the sub-shape addsubshape ("red", 20, 70); // definition of a sub-shape shape red { setfillcolor (200,50,100); rectangle (50,50,100,100); } } //definition of a label shape label { setOrigin ("SW",0,0); println ("Object: #NAME#"); } //definition of a Decoration decoration triangle { // Draw a triangle for the decoration startpath (); moveto (0,30); lineto (50,100); lineto (100,0); endpath (); setfillcolor (153,204,255); fillandstrokepath (); } The shape resulting from this script is: |
Drawing Methods |
Order of declaration |
Shapes can consist of Attribute declarations, Method/Command calls and Sub-shape definitions, which must appear in that order; that is, Attribute declarations must appear before all Method calls and Sub-shape definitions must appear last. |
Shape Attributes Sub-Shapes Drawing Methods |