Dear Endrju & Sobhi,
thank you for your message. I understand that you do want to update the default object name that is generated when creating a new instance of a class to correspond to the value selected in the enumeration field value. To accomplish this, you need to add an event that captures the attribute value change and perform the update accordingly. An important aspect to consider is that the "Name" attribute is used to check for the uniqueness condition within a model (unique name per class needed). You can of course update any other attribute without the restriction of above. Please find the detail on the 2 events that can be used today, as well as an example implementation as code and implementing library.
The GraphRep also considers this change, and shows the "Name" and "Type" value. You can use this of course also to show a completely different representation using the AVAL statement to read values from the attribute and use this in IF statements to change the representation.
-----------------------------------------------------------------
This event is triggered after an attribute value has been changed.
Event name
"SetAttributeValue" 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 value --
-----------------------------------------------------------------
This event is triggered when an attribute value has been edited in a notebook, in the tabular modeling or via a "quick edit" field on the drawing area. It is similar to the "SetAttributeValue" event. The difference is, that attribute value changes which are not initiated by the user, e.g. by import, trigger a "SetAttributeValue" event, but not an "AfterEditAttributeValue" event.
Event name
"AfterEditAttributeValue" 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 LONGSTRING
8 PROGRAMCALL
9 INTERREF
10 EXPRESSION
11 RECORD
12 ATTRPROFREF
13 DATE
14 DATETIME
15 CLOB]
Exit value --
-----------------------------------------------------------------
Example implementation 1ON_EVENT "AfterEditAttributeValue" {
2 # Parameters set by event
3 # instid : integer
4 # attrid : integer
5 # modelid : integer
6 # attrtypeid : integer
7 # 0. Check for class name and only listen/perform action if the class is "Car"
8 CC "Core" GET_CLASS_ID objid: (instid)
9 SETL nCurrentClassID: (classid)
10 CC "Core" GET_CLASS_NAME classid: (nCurrentClassID)
11 SETL sCurrentClassName: (classname)
12 IF (sCurrentClassName = "Car") {
13 # 1. Check for attribute name and only listen/perform action if attribute is "Type"
14 CC "Core" GET_ATTR_NAME attrid: (attrid)
15 SETL sAttrName: (attrname)
16 IF (sAttrName = "Type") {
17 # 2. Get current value of attribute "Type"
18 CC "Core" GET_ATTR_VAL objid: (instid) attrid: (attrid)
19 SETL sTypeValue: (val)
20 # 3. Set an arbitrary attribute value with the exact same value as type
21 CC "Core" SET_ATTR_VAL objid: (instid) attrname: ("Additional name") val: (val)
22 # 4. Set "Name" attribute and also consider the ID (similiar behaviour as for default name creation of instances)
23 CC "Core" SET_ATTR_VAL objid: (instid) attrname: ("Name") val: (val + "-" + STR instid)
24 }
25 }
26}