IBM Support

How to connect ports in IBM Rational Rhapsody using Java API

Question & Answer


Question

How do you connect ports in IBM Rational Rhapsody model using JAVA API?

Cause

You would like to connect ports in Rational Rhapsody model by making use of Java API code instead of using the Graphical Use Interface [GUI]

Answer

In order to connect ports in Rational Rhapsody, you can use of the following piece of JavaScript code:

 
Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.



IRPModelElement mSrcBk = null;    //A block having a source port
IRPModelElement mDstBk=null;    //A block having a destination port
IRPPort mSrcPort=null;    //source port
IRPPort mDstPort=null;    //destination port
IRPGraphNode mGSrcBk=null;
IRPGraphNode mGDstBk=null;
IRPDiagram targetDiag;

//Add your code to assign correct model elements to variables declared above

//Create a link between Src and Dst port and convert it to connector.
IRPLink newlink = mSrcBk.addLinkToElement(mDstBk, null, mSrcPort,mDstPort);
newlink.changeTo("connector");

//Refresh the active view to show the new link
IRPCollection targetElms = app.createNewCollection();
targetElms.addGraphicalItem(mGSrcBk);
targetElms.addGraphicalItem(mGDstBk);
targetDiag.completeRelations(targetElms, 1);
app.refreshAllViews();
 

The code below draws a connector between two ports as you can see below:

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Documentation","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.6.1.4;7.6.1.5;8.0;8.0.1;8.0.2;8.0.3;8.0.4;8.0.5;8.0.6;8.1;8.1.1;8.1.2;8.1.2.1","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21903706