Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Example Scripts
Using Shape Scripts, it is possible to create a wide range of shapes, effects and text statements to enhance the appearance and information value of the elements and connectors you create. Some examples of these scripts are shown in the following table.
Shape Script examples
Code |
Result |
---|---|
Code to add compartments for child elements, with and without editing the parent element.
|
|
// BASIC SHAPES shape main { setfillcolor(255,0,0); // (R,G,B) rectangle(0,0,90,30); // (x1,y1,x2,y2)
setfillcolor(0,255,0); // (R,G,B) ellipse(0,30,90,60); // (x1,y1,x2,y2)
setfillcolor(0,0,255); // (R,G,B) rectangle(0,60,90,90); // (x1,y1,x2,y2) } |
|
// SINGLE CONDITIONAL SHAPE shape main { if (HasTag("Trigger","Link")) {// Only draw if the object has a Tagged Value // Set the fill color for the path setfillcolor(0,0,0); startpath(); // Start to trace out a path moveto(23,40); lineto(23,60); lineto(50,60); lineto(50,76); lineto(76,50); lineto(50,23); lineto(50,40); endpath(); // End tracing out a path // Fill the traced path with the fill color fillandstrokepath(); return; } }
|
|
// MULTI CONDITIONAL SHAPE shape main { startpath(); ellipse(0,0,100,100); endpath(); fillandstrokepath(); ellipse(3,3,27,27);
if (HasTag("Trigger","None")) { return; }
if (HasTag("Trigger","Error")) { setfillcolor(0,0,0); startpath(); moveto(23,77); lineto(37,40); lineto(60,47); lineto(77,23); lineto(63,60); lineto(40,53); lineto(23,77); endpath(); fillandstrokepath(); return; } if (HasTag("Trigger","Message")) { rectangle(22,22,78,78); moveto(22,22); lineto(50,50); lineto(78,22); return; } }
|
|
// SUB SHAPES shape main { rectangle(0,0,100,100);
addsubshape("red", 10, 20); addsubshape("blue", 30, 40); addsubshape("green", 50, 20); addsubshape("red", 100, 20);
shape red { setfillcolor(200, 50, 100); rectangle(0,0,100,100); }
shape blue { setfillcolor(100, 50, 200); rectangle(0,0,100,100); }
shape green { setfillcolor(50, 200, 100); rectangle(0,0,100,100); } }
|
|
// EDITABLE FIELD SHAPE shape main { rectangle(0,0,100,100);
addsubshape("namecompartment", 100, 20); addsubshape("stereotypecompartment", 100, 40);
shape namecompartment { h_align = "center"; editablefield = "name";
rectangle(0,0,100,100); println("name: #name#"); }
shape stereotypecompartment { h_align = "center"; editablefield = "stereotype";
rectangle(0,0,100,100); println("stereotype: #stereotype#"); } }
|
|
// RETURN STATEMENT SHAPE shape main { if(hasTag("alternatenotation", "false")) { //draw ea's inbuild glyph drawnativeshape(); //exit script with the return statement return; }
//alternate notation commands //... rectangle(0,0,100,100); } |
|
//EMBEDDED ELEMENT SHAPE POSITION ON PARENT EDGE shape main { defsize(60,60); startpath();
if(hasproperty("parentedge","top")) { moveto(0,100); lineto(50,0); lineto(100,100); }
if(hasproperty("parentedge","bottom")) { moveto(0,0); lineto(50,100); lineto(100,0); }
if(hasproperty("parentedge","left")) { moveto(100,0); lineto(0,50); lineto(100,100); }
if(hasproperty("parentedge","right")) { moveto(0,0); lineto(100,50); lineto(0,100); } endpath(); setfillcolor(153,204,255); fillandstrokepath();
} |
|
// CLOUD PATH EXAMPLE SHAPE shape main { StartCloudPath(); Rectangle(0,0,100,100); EndPath(); FillAndStrokePath(); } |
|
// CONNECTOR SHAPE shape main { // draw a dashed line noshadow=true; setlinestyle("DASH"); moveto(0,0); lineto(100,0); }
shape source { // draw a circle at the source end rotatable = true; startpath(); ellipse(0,6,12,-6); endpath(); fillandstrokepath(); }
shape target { // draw an arrowhead at the target end rotatable = true; startpath(); moveto(0,0); lineto(16,6); lineto(16,-6); endpath(); fillandstrokepath(); }
|
|
// DOUBLE LINE shape main { setlinestyle("DOUBLE"); moveto(0,0); lineto(100,0); }
|
|
// ROTATION DIRECTION shape main { moveto(0,0); lineto(100,0); setfixedregion(40,-10,60,10); rectangle(40,-10,60,10); if(hasproperty("rotationdirection","up"))
moveto(60,-10); lineto(50,0); lineto(60,10); } if(hasproperty("rotationdirection","down")) { moveto(40,-10); lineto(50,0); lineto(40,10); } if(hasproperty("rotationdirection","left")) { moveto(40,-10); lineto(50,0); lineto(60,-10); } if(hasproperty("rotationdirection","right")) { moveto(40,10); lineto(50,0); lineto(60,10); } }
|
|
// RETURN THE INCOMING AND OUTGOING EDGE FOR CONNECTORS GOING
shape main { //Draw a simple rectangle Rectangle(0,0,100,100);
//Print incoming edges on the element Print("Incoming Edge: #incomingedge#\n");
//Print incoming edges on the element Print("Outgoing Edge: #outgoingedge#\n"); }
|
|
Learn more