Specific considerations are necessary when implementing an AdoScript that is triggered by the "SetAttributeValue" event. The event is triggered by any kind of update/modification on attribute values (by the user or platform) when modifying the model and instances. This is especially of interest in the case of move events, where the event is triggered for any kind of position update and also redraw functions (creation/build up of model).
To implement an AdoScript for the event make sure that you:
- know exactly the cases the AdoScript is implemented for (validation against the attribute ID and its type) to prevent unncessary processing
- make sure that user interaction scripting is targeted to the specific cases (in case of a script during move of objects and relations, the event is continously triggered and the scope is lost)
- for performance considerations, make sure that the script loading is done in effective way, reading and executing AdoScripts on the event potentally results in an unstable and/or time-consuming implementation of your method. It is recommended to pre-load script using the PROCEDURE mechanism and just trigger the respective procedure for each case.
- run type checking (attributeID first and then all other checks) in the ON_EVENT definition, this makes sure that scripts that are not necessary are not loaded just for the checking purpose
The event definition can be found below.
Event name:
"SetAttributeValue"Parameters:instid : integer (ID of the changed instance)
attrid : integer (Attribute ID)
modelid : integer (ID of the model containing the changed instance.
attrtypeid : integer (Attribute type code)
0 INTEGER
1 DOUBLE
2 STRING
3 DISTRIBUTION
4 TIME
5 ENUMERATION
6 ENUMERATIONLIST
7 CORE_LONGSTRING
8 PROGRAMCALL
9 INTERREF
10 EXPRESSION
11 RECORD
12 ATTRPROFREF
13 DATE
14 DATETIME
15 CLOB
oldval : string (The original value (as string))
This is the Core internal value (not UI value).
For attributes of type RECORD this is always an empty string.
The new value can be determined via the "Core" MessagePort.
Exit valueN/AEXAMPLE Implementation: 1ON_EVENT "SetAttributeValue" {
2 EVENT_LOG msgType:"EVENT_LOG" message: ("SetAttributeValue with parameters instid : " + STR instid + " attrid : " + STR attrid + " modelid : " + STR modelid + " attrtypeid : " + STR attrtypeid + " oldval : " + oldval)
3 # CASE A: Validate against AttrID and ClassID - first validation against AttrID, the right-hand part is preloaded in "AppInitialized"
4 IF (attrid = nPreLoadedAttrIDACase) {
5 # ClassID is not part of the event, in case of this attribute ID, get it and only run for specific classes
6 CC "Core" GET_CLASS_ID objid: (instid)
7 SET nClassID: (classid)
8 # Validation against PreloadedClassID, done "AppInitialized" event
9 IF (nClassID = nPreloadedClassIDACase) {
10 # perform action for Case A
11 ...
12 }
13 }
14 # CASE B: Validate against AttrID only
15 IF (attrid = nPreloadedAttrIDBCase){
16 # perform action for Case B
17 ...
18 }
19}