« Back to Fachhochschule Nordwestschweiz FHNW

Update attribute values at different elements

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hello

In my language, there will be different specific document/data modelling elements of which each has a different set of attributes. However, there is some redundancy in the available attributes. So for example there are 3 modelling elements that have an attribute for the name of a person. In order to avoid, that the same data has to be entered for each attribute, whenever a user changes data, it shall be changed at all other elements where the same information is used.

Is there any script or anything available to solve this?

Thanks and best regards,
Pascal

RE: Update attribute values at different elements
Answer
12/1/16 7:23 AM as a reply to Pascal Sibold.
I forgot to mention: the elements that need to be updated can be from/in different modeltypes.

RE: Update attribute values at different elements
Answer
12/5/16 1:36 PM as a reply to Pascal Sibold.
Hello all

Any solution for this? This is my main pain point at the moment.

Thanks in advance and best regards,
Pascal

RE: Update attribute values at different elements
Answer
12/12/16 10:49 AM as a reply to Pascal Sibold.
I managed to do it only on the the same element with the following code:
 1ON_EVENT "AfterEditAttributeValue" {
 2  CC "Core" GET_CLASS_ID objid:(instid)
 3  SETL nCurrentClassID:(classid)
 4  CC "Core" GET_CLASS_NAME classid:(nCurrentClassID)
 5  SETL sCurrentClassName:(classname)
 6  IF (sCurrentClassName = "KoGu") {
 7    CC "Core" GET_ATTR_NAME attrid:(attrid)
 8    SETL sAttrName:(attrname)
 9    IF (sAttrName = "First name") {
10      CC "Core" GET_ATTR_VAL objid:(instid) attrid:(attrid)
11      SETL sTypeValue:(val)
12      CC "Core" SET_ATTR_VAL objid:(instid) attrname:("Last name") val:(val)
13    }
14  } 
15}


Is there any solution to do it:
  1. On another element?
  2. On another element in another model?

RE: Update attribute values at different elements
fread on_event external coupling if get_class_name get_class_id adoscript
Answer
12/6/17 2:25 PM as a reply to Pascal Sibold.
Regarding1.:
The following code updates the value of the attribute “a3” for all objects of class “A” and its subclasses (within a model) whenever the value of “a3” is changed in an object of class “A”.

1) Insert the following code to “Library attributes/Add-ons/Externalcoupling” in your dynamic library:
 1ON_EVENT"AfterEditAttributeValue"
 2{
 3  SETsParams: ("")
 4  SETsParams: (sParams+ "SET nModelId: (" + ( STR modelid) + ")\n")
 5  SETsParams: (sParams+ "SET nInstId: (" + ( STR instid) + ")\n")
 6  SETsParams: (sParams+ "SET nAttrId: (" + ( STR attrid) + ")\n")
 7  SETsParams: (sParams+ "SET nAttrTypeId: (" + ( STR attrtypeid)+ ") \n")
 8  CC"AdoScript" FREAD file: ("%PathToFile%\\update.asc")
 9  #-->RESULT text:strValue ecode:intValue
10  EXECUTE(sParams + text)
11}

2) Insert the following code to the AdoScript file update.asc:
 1CC "Core" GET_CLASS_ID objid: (nInstId)
 2#-->RESULT ecode:intValue classid:intValue
 3SETL nClassID: (classid)
 4
 5CC "Core" GET_CLASS_NAME classid: (nClassID)
 6#-->RESULT ecode:intValue classname:strValue isrel:intValue
 7SETL sClassName: (classname)
 8
 9IF(sClassName = "A") {
10  CC "Core" GET_ATTR_NAME attrid: (nAttrId)
11  #-->RESULT ecode:intValue attrname:strValue
12  SETL sAttrName: (attrname)
13
14  IF(sAttrName = "a3") {
15    CC "Core" GET_ATTR_VAL objid: (nInstId) attrid: (nAttrId)
16    #-->RESULT ecode:intValue val:anyValue
17    SETL sAttrVal: (val)
18   
19    CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (nModelId) classname: (sClassName)
20    #-->RESULT ecode:intValue objids:list
21    SETL lObjids: (objids)
22   
23    FOR i from: (0) to: (tokcnt(lObjids)-1) {
24      CC "Core" SET_ATTR_VAL objid: (VAL (token(lObjids,i))) attrname: (sAttrName) val: (sAttrVal)
25    }
26  }
27}

RE: Update attribute values at different elements
Answer
12/7/17 12:02 PM as a reply to Pascal Sibold.
Regarding 2.:
In order to make the solution in 1. work also outside the current model, some adaptations have to be made in the update.asc file (section 2)). You will find below the adapted code for the update.asc file and the code for the procedure used in update.asc.
In the procedure you use the GET_MODEL_GROUP_TREE_XML, which generates an XML string containing the current model group tree structure. Thus, this XML string also contains modelids of all models. In the next step you search for the <model> tags in the XML string and copy the value of the attribute id to a string called lModelIDs. The result is a list of all modelids. The adaptation in the update.asc file is, that you (FOR-) loop through the modelids list to get the objects of class A from all models. The result is a list of all objects of class A not just from the current model, but from all models.

2) update.asc:
 1CC "Core" GET_CLASS_ID objid: (nInstId)
 2#-->RESULT ecode:intValue classid:intValue
 3SETL nClassID: (classid)
 4
 5CC "Core" GET_CLASS_NAME classid: (nClassID)
 6#-->RESULT ecode:intValue classname:strValue isrel:intValue
 7SETL sClassName: (classname)
 8
 9IF(sClassName = "A") {
10  CC "Core" GET_ATTR_NAME attrid: (nAttrId)
11  #-->RESULT ecode:intValue attrname:strValue
12  SETL sAttrName: (attrname)
13
14  IF(sAttrName = "a3") {
15    CC "Core" GET_ATTR_VAL objid: (nInstId) attrid: (nAttrId)
16    #-->RESULT ecode:intValue val:anyValue
17    SETL sAttrVal: (val)
18
19    SETL lObjids: ("")
20    GET_ALL_MODELIDS lModelIDs: ("") nStartingPointForSearch: (0 ) result:lModelIDs
21    FOR i from: (0) to: (tokcnt(lModelIDs)-1) {
22      CC "Core" LOAD_MODEL modelid: (VAL (token(lModelIDs,i)))
23      #-->RESULT ecode:intValue isloaded:intValue
24      CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (VAL(token(lModelIDs,i))) classname: (sClassName)
25      #-->RESULT ecode:intValue objids:list
26
27      SETL lObjids: (lObjids + objids + " ")
28    }
29    FOR i from: (0) to: (tokcnt(lObjids)-1) {
30      CC "Core" SET_ATTR_VAL objid: (VAL (token(lObjids,i)))attrname: (sAttrName) val: (sAttrVal)
31    }
32  }
33}

3) GET_ALL_MODELIDS procedure:
 1PROCEDURE global GET_ALL_MODELIDS lModelIDs:string nStartingPointForSearch:integer result:reference
 2{
 3  CC "Documentation" GET_MODEL_GROUP_TREE_XML
 4  #--> RESULT ecode:intValue xml:strValue
 5
 6  SETL nClosingRootTagPosition: (search(xml,"</root>",nStartingPointForSearch))
 7  WHILE (nStartingPointForSearch < nClosingRootTagPosition) {
 8    SETL nStartPositionOfGroupTag: (search(xml,"<model",nStartingPointForSearch))
 9    SETL nEndPositionOfGroupTag: (search(xml,">",nStartPositionOfGroupTag))
10    SETL sModelID: (copy(xml,search(xml,"=",nStartPositionOfGroupTag) + 2,
11        (search(xml,"name",nStartPositionOfGroupTag) - search(xml,"=",nStartPositionOfGroupTag)-4)))
12    SETL nStartingPointForSearch: (nEndPositionOfGroupTag)
13
14    IF (nStartingPointForSearch = -1) {
15      BREAK
16    }
17    SETL lModelIDs: (lModelIDs + sModelID + " ")
18  }
19  SETL result: (lModelIDs)
20}