Hello everyone, I am trying to get the object that is connected by generalization to the object I am reading at the moment. I tried all ways to read that connection I know and everything I get to trying to read the target object is a "generalization". As if it could read the connection but not the object to which it links it. Can someone help me please?
var uml2class=omf.toOmfObject(obj.ObjDef());
var classname=uml2class.omfGetName(null);
objDef = obj.ObjDef()
var lista = [];
var objConectados = new Array();
var cnxDefs = objDef.CxnList();
var conList = obj.CxnOccList();
for(var j=0; j<cnxDefs.length; j++) {
if(cnxDefs[j].SourceObjDef().equals(objDef)){
objConectados.push(cnxDefs[j].TargetObjDef());
}else{
objConectados.push(cnxDefs[j].SourceObjDef());
}
lista = obj.getConnectedObjOccs(null, Constants.EDGES_OUT);
var tipo = cnxDefs[j].ActiveType();
var aorigen = cnxDefs[j].SourceObjDef().Name(-1);
var adestino = cnxDefs[j].TargetObjDef().Name(-1);
}
for(var j=0; j<objConectados.length; j++) {
lista[j] = objConectados[j];
}
Hi,
could you clarify what you want your code to say?
Do you want it to say
"Interconnection generalizes Interconnection Circuit.
Interconnection generalizes Interconnection Aggregation Circuit."
or do you want it to say
"Interconnection Aggregation Circuit specializes Interconnection.
Interconnection Circuit specializes Interconnection."
or both?
General pointers, no matter what you want your code to say (advice related to your problem):
- I recommend that you don't start off your problem solving code with switching to the object definition layer - it's not needed and it can even lead to unexpected behaviour: if you reuse the object you're currently reading and call objDef.CxnList() you may get multiple connections of which only one is the one that connects the occurrence you're currently reading with something else.
Anyways, I recommend you try to stick to the occurrence layer, and only punctually dip into the definition layer when you really have to. - There is also no real need to do something like source and target probing of a connection - the "generalizes" connection is a unidirectional relationship - in one way you have the active connection type "generalizes", while in the other way the passive connection type "specializes" says something else about the connected objects. If you just want to know "hey, does this thing I'm currently looking at generalize something", you know exactly that the current occurrence has to be the source occurrence, and at the other end of this outgoing connection, the target occurrence, is the thing that is generalized.
Hi, I have put in the code different ways to get the connected object with generalization that are not working. What I want is for someone to explain to me why none of the shapes gives me the connected object. If they are joined by another connection they work, but not with generalization.
Well I can't really make sense of your code because you're doing some stuff with the object definition layer that I wouldn't touch that much for solving your problem, but the follwoing code works for me with generalization connections in UML 1.4 Class Diagram model types with ARIS 10.0.7 - I connected object occurrences with the object type "Class" symbol type "Class" with generalization connections:
var nLocale = Context.getSelectedLanguage() var selModels = ArisData.getSelectedModels(); var oOutput = Context.createOutputObject(); for each(var selModel in selModels) { oOutput.OutputTxt(selModel.Name(nLocale) + "\n\n"); var allOccs = selModel.ObjOccList(); for each(var singleOcc in allOccs) { var outgoingGeneralizationCxns = singleOcc.Cxns(Constants.EDGES_OUT).filter(filterConGeneralization); for each(var singleOutgoingGeneralizationCxn in outgoingGeneralizationCxns) { oOutput.OutputTxt(singleOcc.getObjDefName(nLocale) + " generalizes " + singleOutgoingGeneralizationCxn.getTarget().getObjDefName(nLocale) + "\n"); } oOutput.OutputTxt("\n"); var incomingGeneralizationCxns = singleOcc.Cxns(Constants.EDGES_IN).filter(filterConGeneralization); for each(var singleIncomingGeneralizationCxn in incomingGeneralizationCxns) { oOutput.OutputTxt(singleOcc.getObjDefName(nLocale) + " specializes " + singleOutgoingGeneralizationCxn.getSource().getObjDefName(nLocale) + "\n"); } } oOutput.OutputTxt("\n\n"); } oOutput.WriteReport() function filterConGeneralization(singleConOcc){ return singleConOcc.Cxn().TypeNum() == Constants.CT_GENERAL; }
I only make use of the object definition layer once when I ask for the connection type in my custom filter method, everything else happens on the object occurrence layer.
Hmm, that's odd.
Have you tried using the debugger? Set breakpoints and go through the script line by line, checking the state of variables throughout the script execution. You can also partially execute lines by using the debugger tab that gives you a line where you can execute commands. E.g. when the debugger stops before executing the line
var outgoingGeneralizationCxns = singleOcc.Cxns(Constants.EDGES_OUT).filter(filterConGeneralization);
you can just copy
singleOcc.Cxns(Constants.EDGES_OUT)
and add a ".length" at the end to find out how many connections in general it finds without any filtering going on.
The trick is to play around with the debugger and that debugger-line for a while, e.g. use singleOcc.getObjDefName(nLocale) to find out what object occurrence you're currently looking at, take a look at the diagram to find out how many connections it should return and after that do singleOcc.Cxns().length to find out how many connections it actually returns.
If you use the debugger engough you should be able to narrow down which exact method isn't returning what you expect it to return.
I understand that the question seems new user, but I have been working with ARIS script for a year. I have created scripts that read folders and show all the attributes of all objects, showing the information contained in the stereotypes and output the result in excel or word. I can read connections made between an attribute and an object and display it. It is only with generalization connections that I cannot get the connected object.
I have tested your code and used the debuger but it just doesn't detect the connections. With my code it reads the connection and when trying to obtain the source or destination object it simply returns a "Generalization".