SW

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); 
by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Wed, 04/26/2017 - 08:24

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;

}

 

0
by Scott Waddell Author
Posted on Wed, 04/26/2017 - 08:55

In reply to by rgoldenbaum

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;
}

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock