Rhapsody Automation: How to add InterfaceBlock for ProxyPort using java program?
I am trying to do some automation in Rhapsody for creating Internal Block Diagram.
IRPPackage rpPackage= findPackage(project, "Package2");
IRPPort port= (IRPPort)rpPackage.findNestedElementRecursive("Proxy_Ports_1", "ProxyPort");
IRPClass element = (IRPClass)rpPackage.findNestedElementRecursive("TESTINTERFACEBLOCK", "InterfaceBlock");
port.addProvidedInterface(element);
Error:
Exception in thread "main" com.telelogic.rhapsody.core.RhapsodyRuntimeException: Cannot modify read only element (or element with read only owner)
C:\ProgramData\IBM\Rational\Rhapsody\8.3x64\Share\Profiles\SysML\SysMLProfile_rpy\SysML.sbs.
at com.telelogic.rhapsody.core.RPPort.addProvidedInterfaceNative(Native Method)
at com.telelogic.rhapsody.core.RPPort.addProvidedInterface(Unknown Source)
Note:
I have manually added the InterfaceBlock with ProxyPort and trying the fetch the information through program.
It is working as expected and find the code used to fetch the information.
IRPCollection providedInterfaces = element.getProvidedInterfaces();
IRPModelElement item2 = (IRPModelElement) providedInterfaces.getItem(1);
System.out.println(item2.getName());
As I have used the same API(ProvidedInterface) to add InterfaceBlock, it should work as expected.
Kindly guide me to resolve the error.
One answer
Code:
IRPPackage rpPackage= findPackage(project, "Package2");
IRPPort port= (IRPPort)rpPackage.findNestedElementRecursive("Proxy_Ports_1", "ProxyPort");
IRPClass element = (IRPClass)rpPackage.findNestedElementRecursive("TESTINTERFACEBLOCK", "InterfaceBlock");
port.addProvidedInterface(element);
In the above code, instead of addProvidedInterface method, use setContract.
Then it is working as expected.
"port.setContract(interfaceBlock);"
Comments
Vijayanand Karunanithi
Mar 06 '19, 12:52 a.m.Is there any updates on the reported query?