Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Example Scripts

You can create a wide range of shapes, effects and text statements using Shape Scripts, to enhance the appearance and information value of the elements and connectors you create. Some examples of such scripts are provided here.

Access    Settings | UML Types > Stereotypes (specify stereotype): Shape Script + Assign or
Settings | UML Types > Stereotypes (specify stereotype): Shape Script + Edit

Shape Script examples

Script

Shape

 

// 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)

}

 

ShapeScripts_Example1

 

 

// SINGLE CONDITIONAL SHAPE

shape main

{

if (HasTag("Trigger","Link"))

{// Only draw if the object has a Tagged Value
 // Trigger=Link

// 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;

}

}

 

 

ShapeScrips_Example4

 

// MULTI CONDITIONAL SHAPE

shape main

{

startpath();

ellipse(0,0,100,100);

endpath();

fillandstrokepath();

ellipse(3,3,97,97);

 

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;

}

}

 

 

ShapeScrips_Example7

 

ShapeScrips_Example6

 

// SUB SHAPES

shape main

{

rectangle(0,0,100,100);

 

addsubshape("red",   10,  20);

addsubshape("blue",  30,  40);

addsubshape("green"50,  20);

addsubshape("red",   10020);

 

shape red

{

setfillcolor(20050100);

rectangle(0,0,100,100);

}

 

shape blue

{

setfillcolor(10050200);

rectangle(0,0,100,100);

}

 

shape green

{

setfillcolor(50200100);

rectangle(0,0,100,100);

}

}

 

 

SubShapes

 

// EDITABLE FIELD SHAPE

shape main

{

rectangle(0,0,100,100);

 

addsubshape("namecompartment"10020);

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#");

}

}

 

 

EditableFieldShape

 

// RETURN STATEMENT SHAPE

shape main

{

if(hasTag("alternatenotation""false"))

{

//draw ea's inbuild glyph

drawnativeshape();

//exit script with the return statement

return;

}

else

{

//alternate notation commands

//...

rectangle(0,0,100,100);

}

}

ReturnStatement2

RetrnStatement1

 

 

//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();

 

}

Script2

 

Script1Script4Script3

 

 

// CLOUD PATH EXAMPLE SHAPE

shape main

{

    StartCloudPath();

    Rectangle(0,0,100,100);

    EndPath();

    FillAndStrokePath();

}

CloudPathExample

 

 

// 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();

}

 

 

NewConnector

 

// DOUBLE LINE

shape main

{

setlinestyle("DOUBLE");

moveto(0,0);

lineto(100,0);

}

 

 
                DoubleLineConn

 

// 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);

}

}

 

 

 

                      ROTDIR1

 

                            ROTDIR2

 

// GET A VALUE RETURNED BY AN ADD-IN

shape main

{

       //Draw a simple rectangle

       Rectangle(0,0,100,100);

 

       //Print string value returned from Add-In "MyAddin",

       //Function "MyExample" with two string parameters

       Print("#ADDIN:MyAddin, MyExample, param1, param2#");

}

 

// METHOD SIGNATURE FOR ADD-IN FUNCTION:

// Public Function MyExample(Repository As EA.Repository,

// eaGuid As String, args As Variant) As Variant

 

AddInShape

 

// ADD CUSTOM COMPARTMENTS BASED UPON CHILD ELEMENTS

 

( See Add Custom Compartments to Element )

 

ShapeScriptCompartmentExample

 

 

// RETURN THE INCOMING AND OUTGOING EDGE FOR CONNECTORS
// GOING INTO AND OUT OF AN OBJECT

 

shape main

{

       //Draw a simple rectangle

       Rectangle(0,0,100,100);

 

       //Print incoming edges on the element

       Print("Incoming Edge: #incomingedge#\n");

 

      //Print outgoing edges on the element

       Print("Outgoing Edge: #outgoingedge#\n");

}

connectorpoint1

 

 

connectorpoint2

 

 

Learn more

Learning Center topics

(Alt+F1) | Modeling Languages | Defining Shapes | Defining an Element Shape
(Alt+F1) | Modeling Languages | Defining Shapes | Defining a Connector Shape