Hi,
I am developing a small script that should be able to import excel data and generate a model.
However, I am unable to get connections between some objects of specific types, even though these connections can be created in the "Designer" module.
Concrete illustration of my problem:
As you can see, there are some links missing. It WOULD work if the "Position" would be, for example, a "Function".
I try to connect (all) the objects with the following function:
function connect (source, target) { // This function "brute force" connects two objects var i = 0; var connection = null; while(!connection && i < 1000) { connection = model.CreateCxnOcc(true, source, target, i++, pointList); } //if(!connection) Dialogs.MsgBox("Still no connection") }
so I think we can exclude that I chose the wrong CxnType (Type number of the relationship occurrence to be created -- in this case: i).
So, has anybody got an idea what could be the problem or has a different solution / workaround for this?
If you need some more code, please feel free to ask!
Many thanks,
Laurent
Hi Laurent -
Why are you not just setting the connection type in the code rather than iterating through 1000 connection types? This should work:
function connect (model, source, target) { var cxnType = null; var connection = null; var sourceType = source.ObjDef().TypeNum(); var targetType = target.ObjDef().TypeNum(); if ((sourceType == Constants.OT_EVT) && (targetType == Constants.OT_FUNC)) { // Event >> activates (43) >> Function cxnType = Constants.CT_ACTIV_1; } else if ((sourceType == Constants.OT_PERS_TYPE) && (targetType == Constants.OT_FUNC)) { // Person Type >> carries out (218) >> Function cxnType = Constants.CT_EXEC_2; } else if ((sourceType == Constants.OT_POS) && (targetType == Constants.OT_FUNC)) { // Position >> carries out (65) >> Function cxnType = Constants.CT_EXEC_1; } if (cxnType != null) { connection = model.CreateCxnOcc(true, source, target, cxnType, pointList); } return; }
Hi Ellen,
First of all, thank you for your answer. It pointed me in the right direction and my script works now :)
I was not setting the exact connection type because
- I wanted to save time and
- because I didn't know to which object combinations the different types belong to.
I tried your code, and much to my regret it didn't solve my problem either (which was to be expected, as all those constant values were already covered by my function). However, I noticed that the argument order plays a major role here: a "Position" has to be the source of the connection. Therefore, I updated my function as follows:
function connect (source, target, stop) { // This function "brute force" connects two objects var i = 0; var connection = null; while(!connection && i < 1000) { connection = model.CreateCxnOcc(true, source, target, i++, pointList); } if(!connection && typeof(stop) == 'undefined') connect(target, source, true); }Short explanation: If the connection fails, try swapping the source and target value and try again -- straight and simple :)
Again, thank you very very much for your help!
Thanks,
Laurent