ARIS Community - We Love BPM

Programatically creating a new connection

scotty595's picture
by Scott Waddell in Reports & Macros posted on 2017-04-26

Hi All,

I'm trying to programmatically create a connection between 2 objects. I've created a script which detects if the objects overlap, and then I want to create the connection using CreateCxnOcc. I've tried a few different options, but can't seem to get the connection created.

Even if I go to a basic EPC model and select an Event and a Function, and use the below code the connection isn't created - I feel like I must be doing something wrong!

I'm not a programming expert by any stretch but can generally get by, so appreciate the help and sorry if I'm missing some basics.

 

var objects = ArisData.getSelectedObjOccs();
var model = objects[0].Model();
var cnx = model.CreateCxnOcc(false,objects[1],objects[0],Constants.CT_ACTIV_1,null); 
5494 Views
0 Likes
2 Comments
Sorry there are no tags
There are no attachments
Robert Goldenbaum posted on 2017-04-26

Hi Scott,

well, you need a point list for a cxn occ (meaning an occurrence of a connection in a model). So you need the start point, the end point and also a point for every corner...

If you want to create nested objects, I don't think you have to create a cxn occ. A cxn def could be enough...

An example to create a connection follows below...

naPointList = GetPointList(oAWSTOcc_New, oNewObjOcc);
oCxnOcc = oSyncModel.CreateCxnOcc(oAWSTOcc_New, oNewObjOcc, Constants.CT_CAN_SUPP_1, naPointList, false, false);
 

function GetPointList(oSrc, oTrg){
    var oPointList = new Array();
    var oPoint = null;
    var oPoint2 = null;
    var oPoint3 = null;
    var oPoint4 = null;
    
//    oPoint = new java.awt.Point(oSrc.X() + oSrc.Width(), oSrc.Y() + oSrc.Height() / 2);
//    oPoint2 = new java.awt.Point(oSrc.X() + oSrc.Width() + (oTrg.X() - (oSrc.X() + oSrc.Width())) / 2, oSrc.Y() + oSrc.Height() / 2);
//    oPoint3 = new java.awt.Point(oSrc.X() + oSrc.Width() + (oTrg.X() - (oSrc.X() + oSrc.Width())) / 2, oTrg.Y() + oTrg.Height() / 2);
//    oPoint4 = new java.awt.Point(oTrg.X(), oTrg.Y() + oTrg.Height() / 2);

//    oPointList.push(oPoint);
//    oPointList.push(oPoint2);
//    oPointList.push(oPoint3);
//    oPointList.push(oPoint4);
    
    oPoint = new java.awt.Point(oSrc.X(), oSrc.Y() + oSrc.Height() / 2);
    oPoint2 = new java.awt.Point(oTrg.X() + oTrg.Width(), oTrg.Y() + oTrg.Height() / 2);
    
    oPointList.push(oPoint);
    oPointList.push(oPoint2);
    
    return oPointList;
}
 

Scott Waddell posted on 2017-04-26

Thanks Robert, your help has been invaluable!

 

My final code is working and now automatically creates implicit connections from all object occurrences to the Quick Object they are contained within.

For anyone else interested, final code:


var objects = ArisData.getSelectedObjOccs();
  
for(var i=0; i<objects.length; i++ )
{
    if(objects[i].ObjDef().Type()=="Quick object"){
        var model = objects[i].Model();
        for(var j=0; j<objects.length; j++ )
            {    
                if(isCollide(objects[i], objects[j])){
                    if(objects[i]!==objects[j]){
                        naPointList = GetPointList(objects[j], objects[i]);

                        var cnx = model.CreateCxnOcc(false,objects[j],objects[i],Constants.CT_IS_A,naPointList); // creation of connection
                }
                }
            }
   }
}
 
 
 function isCollide(a, b) {
    return !(
        ((a.X() + a.Height()) < (b.Y())) ||
        (a.Y() > (b.Y() + b.Height())) ||
        ((a.X() + a.Width()) < b.X()) ||
        (a.X() > (b.X() + b.Width()))
    );
}

function GetPointList(oSrc, oTrg){
    var oPointList = new Array();
    var oPoint = null;
    var oPoint2 = null;
    var oPoint3 = null;
    var oPoint4 = null;

    
    oPoint = new java.awt.Point(oSrc.X(), oSrc.Y() + oSrc.Height() / 2);
    oPoint2 = new java.awt.Point(oTrg.X() + oTrg.Width(), oTrg.Y() + oTrg.Height() / 2);
    
    oPointList.push(oPoint);
    oPointList.push(oPoint2);
    
    return oPointList;
}