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

Query Methods

When you are using IfElse statements in a Shape Script, the condition is usually that the object has a certain tag or property, and possibly if that tag or property has a particular value. You can set up the conditional statement to check for the property and value using one of the two query methods described below.

Queries

Method

Description

See also

boolean HasTag(
 string tagname,
 ( string tagvalue ) )

Evaluates to true if the associated element has a tag with the name tagname.

If the second parameter tagvalue is provided, the tag tagname must be present, and the value of the tag has to be equal to tagvalue for the method to evaluate to true.

 

Tagged Values

boolean HasProperty(
 string propertyname,
 ( string propertyvalue ) )

Evaluates to true if the associated element has a property with the name propertyname.

If the second parameter propertyvalue is provided, the property must be present, and the value of the property has to be equal to propertyvalue for the method to evaluate to true.

 

Display Element/Connector Properties

 

HasProperty and user-selected settings

A particular application of the HasProperty() method is to check for property settings where you have provided the facility for the user to set that property for a specific instance of use of the stereotyped element. So, the user can drag the element onto the diagram and, through the element context menu, set one  or more properties that the Shape Script responds to in rendering the diagram object. The element might, therefore, have one appearance on one diagram but a different appearance on another, because it has different property settings on the two diagrams.

To specify user-selectable properties in your Profile, create the appropriate Stereotype element and - for each property being defined - add an attribute with the stereotype «diagram property» to this element. For the attribute name, type the text of the option that will display on the context menu for the stereotyped element; for example, Is Red. Also give the attribute an alias, which would be the name of the property as it is stored and which the HasProperty() method will evaluate. If you set the attribute's initial value to 1, the context menu option will initially be set; if there is no initial value, the property option will default to not set.

Also define an _image attribute with a Shape Script that applies the HasProperty() method. In this example, the Shape Script defines two Class properties (Is Red and Is Triangle) for the HasProperty () method to check whether the option is set or not.

 

shape main

{

 if (HasProperty("IsRed","1"))

 {

         SetFillColor(255,128,128);

 }

 

 if (HasProperty("IsTriangle","0"))

 {

         Polygon(50,50,3,50,0);

 }

 else

 {

         DrawNativeShape();

 }

}

 

 

When the Stereotype for the extended element type is defined, it will resemble this:

RedProfile

 

After the MDG Technology is created and released to your users, when they drag the stereotyped element from the Toolbox it will be rendered according to current settings for the defined properties, which the users can access and re-set through the context menu, as shown:

 

redstyle

Learn more