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:
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:
![](/support/pages/system/files/support/swg/rattech.nsf/0/ed400f2dd00146cc85257e4d002ac0ef/Content/0.94E.gif)
Related Information
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21903706