« Back to University of Vienna - OMILAB

getting objects of other models

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
getting objects of other models
Answer
1/9/19 1:49 PM
I would like to get some objects from other models in my modelgroup.  However, the debugger receives an error message that the model does not exist. I get the modelid, the correct modelname and there are defined objects of the class in the model but the access to a specific object is not possible.

I tried this code but the returned objids in line 23 is always empty.
 1ON_EVENT "AfterEditAttributeValue" {
 2#The parameter instid contains the model ID of the modified instance,
 3#attrid the ID of the changed attribute, modelid the ID of the model containing the modified instance and attrtypeid the attribute type code
 4SET veränderteAttrid:(attrid)
 5SET veränderteModelid:(modelid)
 6CC "Core" GET_CLASS_ID objid:(instid)
 7SET veränderteClassid:(classid)
 8CC "Core" GET_CLASS_ID classname: "Kalender"
 9SET kalenderClassid:(classid)
10IF ((veränderteClassid) = (kalenderClassid)) {
11  CC "Core" GET_MODELGROUP_ID mgroupname: "Models" sep:" "
12   CC "AdoScript" INFOBOX ("modelgroupid " + STR(mgroupid))
13   CC "Core" GET_MODELGROUP_MODELS mgroupid: (mgroupid)
14   CC "AdoScript" INFOBOX ("modelle " + (modelids))
15   FOR mid in:(modelids) {
16     CC "AdoScript" INFOBOX ("mid: " + mid)
17     CC "AdoScript" INFOBOX ("current model id: " + (mid))
18     CC "Core" GET_MODEL_MODELTYPE modelid:(VAL mid)
19     IF ((modeltype)="Lehrveranstaltung") {
20                                 CC "Core" GET_MODEL_INFO modelid:(VAL mid)
21                                 CC "AdoScript" INFOBOX ("current model name: " + modelname)
22                                 CC "Modeling" OPEN modelids:(mid)
23                                 CC "Core" debug GET_ALL_OBJS_OF_CLASSNAME modelid:(VAL mid) classname:("Vorlesung")
24                                 CC "AdoScript" INFOBOX (" found objs: " + objids)
25                                 #CC "Modeling" CLOSE modelids:(mid)
26     }       
27   } 
28  }
29}

Why is the objids empty and why does the error message say that the model does not exist?

You find the library in the attachment. The error occurs in the modeltype “Menschen” when an attribute is changed for the class “Kalender”. The script should find all objects of the classname “Vorlesung” in the modeltype “Lehrveranstaltung”. 
Attachments: LectureOrganization Probleme.abl (96.8k)

RE: getting objects of other models
Answer
6/13/14 9:06 AM as a reply to Tamara Gurschler.
Dear Tamara,
the problem in your code fragment relates to the call of GET_MODELGROUP_MODELS. The returned IDs of this call are "modelthread" IDs, not "modelversion" IDs. You can get the modelversion IDs by adding the parameter "getversionids" to the call. Alternatively, you can retrieve modelversion IDs from modelthread IDs using GET_ALL_MODEL_VERSIONS_OF_THREAD modelthreadid:id. Potentially this call can return multiple versions of the modelthread.

The update code fragment:
 1ON_EVENT "AfterEditAttributeValue" {
 2# ....
 3CC "Core" debug GET_MODELGROUP_ID mgroupname: "Models" sep:" "
 4CC "Core" debug GET_MODELGROUP_MODELS mgroupid: (mgroupid) [b]getversionids[/b]
 5FOR mid in: (modelids) {
 6  CC "Core" debug GET_MODEL_MODELTYPE modelid: (VAL mid)
 7  IF ((modeltype)="Lehrveranstaltung") {
 8    CC "Core" debug GET_MODEL_INFO modelid: (VAL mid)
 9    # Um das Modell zu lesen, steht auch der Aufruf LOAD_MODEL zur Verfügung
10    CC "Modeling" OPEN modelids: (mid)
11    CC "Core" debug GET_ALL_OBJS_OF_CLASSNAME modelid: (VAL mid) classname: ("Vorlesung")
12  }    
13}