Question & Answer
Question
Cause
Answer
Accessing and Editing model properties with the Rhapsody API
- Rhapsody diagrams consist of graphic representations of model elements: graphic elements. Diagram graphic elements consist of just three types:
IRPGraphNode
,IRPGraphEdge
andIRPGraphElement
. - The attributes of graphical elements are determined by their graphic properties. They are not accessible in the user interface, but can be read and modified with the API methods:
getGraphicalProperty()
andsetGraphicalProperty().
- The
getGraphicalElements()
method returns an IRPCollection containing these elements. -
You can retrieve the model element from any corresponding graphic element using the getModelElement() method. However, not all graphic elements have a matching UML model element. For example, Notes and Swimlane Frames do not represent a model element in the browser. In this case getModelElement() will return a null pointer, so you must be careful when processing their properties. In the example below, you can see how a try/catch statement can be used to handle graphic elements with and without a matching model element.
As always, check the API reference guide in the <RhapsodyInstallation>\Doc\java_api directory.
import com.telelogic.rhapsody.core.*; public class ReadGraphicProperties { public static main(String[] args) { IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication(); IRPModelElement el = app.getSelectedElement(); if (el instanceof IRPDiagram) { IRPDiagram diagram = (IRPDiagram)el; System.out.println(diagram.getMetaClass()); List<IRPGraphElement> diagramElements = diagram.getGraphicalElements().toList(); for (IRPGraphElement graphElement : diagramElements) { List<IRPGraphicalProperty> graphicalPropeties = null; try { /// in case the diagram graphic has no corresponding model element System.out.println(graphElement.getModelObject().getMetaClass()); System.out.println("=========="); graphicalPropeties = graphElement.getAllGraphicalProperties().toList(); for (IRPGraphicalProperty graphProp : graphicalPropeties) { System.out.println(graphProp.getKey() + "\t" + graphProp.getValue()); } } catch (Exception e) { // diagram graphic has no corresponding model element. // graphic element may contain a "Type" graphical property System.out.println("<Unknown> Model Element"); System.out.println("======================="); IRPCollection gps = graphElement.getAllGraphicalProperties(); for (int i=0; i < gps.getCount(); i++) { IRPGraphicalProperty gp = (IRPGraphicalProperty) gps.getItem(i); if (gp != null) // Null graphical properties may exist System.out.println(gp.getKey() + "\t" + gp.getValue()); } } } } } } }
Note: All property values must be set as strings.
Attribute Name | Applicable to | Possible Values | Notes |
AttributesDisplay |
Class | None or All or Public or Explicit |
|
BackgroundColor |
All | Int,int,Int | |
ForegroundColor |
All | Int,int,Int | |
GUID |
All | Standard Rhapsody GUID | |
Height |
Class, Object, State | Int | |
LineStyle |
Association, Port | Straight or Spline or u dRectilinear |
|
LineWidth |
All | Integer | |
OperationsDisplay |
Class | None or All or Public or Explicit | |
Position |
All | Int, Int | |
ShowName |
All | Full_Path or Relative or Name_Only or Label | |
ShowStereotypeLabel |
All | TRUE or FALSE |
|
SourcePosition |
Association, Port | Int, int | |
TargetPosition |
Association, Port | Int, Int | |
StructureView |
Class, Object, State | True or False |
|
Text |
All | String |
|
TextColor |
All | Int, Int, Int | |
TextFontBold |
All | 700 or 400 (True or False ) |
|
TextFontItalic |
All | 1 or 0 (True or False ) |
|
TextFontName |
All | Check font list | |
TextFontSize |
All | Int | |
TextPosition |
All | Int, Int | Read only |
Type |
All | String |
|
Width |
Class, Object, State | Int |
Related Information
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21383978