IBM Support

How to copy a Statechart Diagram from one project to another using JAVA API in Rational Rhapsody

Question & Answer


Question

How do you copy a Statechart Diagram from one project to another using JAVA API in IBM Rational Rhapsody?

Cause

You would like to use Java Application Programming Interfaces (API) code to automate the manual task to be performed with in Rational Rhapsody or to achieve something that is not possible through the Rhapsody GUI.

Answer

In order to copy Statechart Diagram from one project and copy in another using JAVA API in Rational Rhapsody you can use the below code as a reference. The code can be enhanced to include other specific element types.

 
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.



import com.telelogic.rhapsody.core.IRPApplication;

import com.telelogic.rhapsody.core.IRPModelElement;

import com.telelogic.rhapsody.core.IRPProject;

import com.telelogic.rhapsody.core.IRPStatechart;

import com.telelogic.rhapsody.core.RhapsodyAppServer;

public class CopyElements {

public static void main(String[] args) {

try {

IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();

IRPProject myPrj1 = myApp.openProject("C:\\RhapsodyProject\\RhapsodyProject.rpy"); //location of first project

IRPStatechart mySC = (IRPStatechart) myPrj1.findNestedElementRecursive("Test_statechart_1", "Statechart");  //name of State Chart

IRPProject myPrj2 = myApp.insertProject("C:\\RhapsodyProjectSecond\\RhapsodyProjectSecond.rpy"); //location of Second project

IRPModelElement myEle = myPrj2.findNestedElementRecursive("R_Class_1","Class");//Name of the class

mySC.clone("Test_statechart_1", myEle);

myPrj2.save();

myPrj1.close();

} catch ( RuntimeException e) {

System.out.println("Problem : " + e);

}

}

}

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF016","label":"Linux"}],"Version":"8.0.2;8.0.1;8.0;7.6.1.3;7.6.1.2;7.6.1.1;7.6.1;7.6.0.1;7.6","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21638531