Changing connector styles using Open API

Visual Paradigm support diagramming with various connector styles. In this article we will show you how to change the style of a connector using Open API. We will use class diagram and association as example to demonstrate how to change the connector style.

Suppose we already have a class diagram like this opening in Visual Paradigm.

Original class diagram in Visual Paradigm

First we have to retrieve this diagram from project. We can use the DiagramManager.getActiveDiagram() method to obtain the opening diagram.

IDiagramUIModel diagram = ApplicationManager.instance().getDiagramManager().getActiveDiagram();

Next we loop through the shapes in the diagram to find out the association and cast it to IAssociationUIModel type.

IDiagramElement[] elements = diagram.toDiagramElementArray();
for (IDiagramElement element : elements) {

Once the association is found we can obtain its connector style using the IAssociationUIModel.getConnectorStyle() method. If it is already in curve style (arc) then we change it to round rectilinear style, otherwise change it to arc. You can find the constants for various connector styles under IConnectorUIModel class (those starting with CS_).

if (element instanceof IAssociationUIModel) {
  IAssociationUIModel associationShape = (IAssociationUIModel) element;
        
  if (IConnectorUIModel.CS_ARC == associationShape.getConnectorStyle()) {
    associationShape.setConnectorStyle(IConnectorUIModel.CS_ROUND_RECTILINEAR);
  } else {
    associationShape.setConnectorStyle(IConnectorUIModel.CS_ARC);					
  }
}

Sample plugin

The sample plugin attached demonstrate how to change the layout of the active diagram. After you deploy the plugin into Visual Paradigm you can create a class diagram with classes connected with associations. To demonstrate the curve line style it is recommend to create turning points on the associations. After that click on the plugin button in application toolbar will switch the association between curve and round rectilinear styles.

Trigger sample plugin

Download sample plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply