On this page
You can retrieve, modify, add, or remove structural feature values using the Action Language Helper (ALH) API and action scripts in the modeling tool. ALH allows you to dynamically control object properties, and update data during a simulation. You can also retrieve tag values, which store additional metadata.
Getting a structural feature value
You can use script to get a structural value. You can use the fUML object syntax, with the object.get("featureName"). featureName can use dot notation for nested features. For example:
- value = self.get("car.speed");
Using Groovy scripting language, you can get nested structural features using just dot notation. For example, value=car.speed
Alternatively, structural value can also be acquired using ALH API.
ALH.getValue(object, "featureName")
The following example shows how to get the value of the structural feature indicated above in ALH API.
value = ALH.getValue(self, "car.speed");
Information
While using Rhino JavaScript, the return value of ALH.getValue() is not automatically UnBoxed to a primitive type. Users need to handle such UnBoxing by themselves, by using ALH.getValue(object, "speed").intValue() to get the value of primitive integer type.
Specifying a structural feature value
You can use script to specify a structural value. You can use the fUML object syntax, with the object.set("featureName", value). featureName can use dot notation for nested features. For example:
- value = self.set("speed", 10);
Using Groovy scripting language, you can set nested structural features using just dot notation. For example, car.speed=100
Alternatively, structural value can also be specified using ALH API.
ALH.setValue(object, "featureName", value)
The following example shows how to specify the value of the structural feature in ALH API:
value = ALH.setValue(self, "speed", 10);
In addition, the RuntimeObject can be omitted. The following example shows how to set a structural feature value without specifying a RuntimeObject in ALH API:
ALH.setValue("featureName", value)
Adding a value to an object
You can use script to add a value to an object. You can use the fUML object syntax, with object.addValue("featureName", value) and object.addValueAt("featureName", value, insertAt). For example:
- self.addValue("p1",10); // System.p1 = [10]
- self.addValue("p1",30); // System.p1 = [10, 30]
- self.addValueAt("p1",20,2); // System.p1 = [10, 20, 30]
Alternatively, structural value can also be added using ALH API.
ALH.addValue(object, "featureName", value)
If you have more than one value in an object and if you want to add a value at a specific position, you can use insertAt argument.
ALH.addValueAt(object, "featureName", value, insertAt)
The following code fragment shows how to add values to an object, e.g., System.p1, through ALH API.
ALH.addValue(self,"p1",10); // System.p1 = [10] ALH.addValue(self,"p1",30); // System.p1 = [10, 30] ALH.addValueAt(self,"p1",20,2); // System.p1 = [10, 20, 30]
Removing a value of an object
You can use script to remove a value from an object. You can use the fUML object syntax, with object.removeAt("featureName", removeAt). For example:
- print(self); // System.p1 = [10, 20, 30]
- self.removeAt("p1",3); // System.p1 = [10, 20]
If feature has only one value, removeAt index 1 should be used.
Alternatively, structural value can also be removed using ALH API.
ALH.removeValueAt(object, "featureName", removeAt)
You can also use the fUML object syntax, with object.remove("featureName", objectToRemove) to remove an exact fUML object from a feature. For example:
- self.remove("myPart", myPart)
object.remove("featureName", object) is useful when you have direct reference to fUML object you want to remove. Remove can be used in conjunction with get method to get a direct reference to the fUML object.
Alternatively, structural value can also be removed using ALH API.
ALH.removeValue(object, "featureName", objectToRemove)
Getting a tag value
You can use script to get a tag value. You can use the fUML object syntax, with object.getTagValue("tagName"). For example:
- self.getTagValue("uniform.max"); // 10
Alternatively, tag value can also be acquired using ALH API.
ALH.getTagValue(object, "tagName")
If the RuntimeObject is omitted, $context$ or self will be used as an object. The context object in the parametric is the constraint block object that owns the constraint, not the actual context of the diagram. The following example shows how to get a tag value without specifying a RuntimeObject in ALH API:
ALH.getTagValue("tagName")
The following code fragment shows how to get tag values, e.g., max, through ALH API. Also refer to Value access and references by tags.
ALH.getTagValue(self, "uniform.max"); // 10