Cameo Simulation Toolkit: HOWTO test an EnumerationLiteral value in a (Groovy) script in an OpaqueAction/Behavior. Use kind.name == "value"

Icon class
icon_class
far fa-sticky-note
icon_class_computed
far fa-sticky-note
Note kind
Policy level
Specification keywords
UML keywords
SysMLv1.x keywords
Keywords

The following has been tested for Groovy as scripting language, but "should" work for other scripting languages supported by Magic Model Analyst® (Cameo Simulation Toolkit®).

Let's say you have a an Enumeration EnumKind with EnumerationLiterals apple and orange, and the input argument to the script is kind:EnumKind.

If you just want to print an EnumerationLiteral Cameo will handle it like a String, so simply:

println("kind: " + kind);
But to test the value you need to use kind.name == "STRINGVALUE", like this:
println("colour: " + (kind.name == "apple" ? "red" : "orange")  );

BTW: As of v2024x, if you reference an Enumeration value property via self "weird" things can happen with Enumeration value comparisons. If a script is in the context of the owner of the Enumeration value property (such as an OpaqueBehavior as 'method' of an Operation) just refer to it directly. So if the Enumeration value property is kind:EnumKind, just refer to it as kind not as self.kind in the script. Strangely, in the case of Groovy, self.kind worked fine for Enumeration comparisons in the simulation console, but not in the actual script. "Weird" indeed.

Relates to
Related notes
Related notes (backlinks)
Related snippets (extracts)
Visit also
Visit also (backlinks)