Retrieve Flow Sequence in Business Process Diagram using Open API

tomcat-thumbVisual Paradigm’s Open API is a powerful tool which allow user to extend the functionalities of Visual Paradigm software. Open API provide full access to the model information within the project, and user can retrieve the diagram and model information in programmatic approach. For most of the case user can obtain the diagram and model information as a collection where the elements are sorted based on the creation order. But in Business Process Diagram there is a special way to retrieve the elements according to their flow order. In this article we will show you how it works.

Obtain the active Business Process Diagram

First we obtain the business process diagram currently opening:

IDiagramUIModel diagram = ApplicationManager.instance().getDiagramManager().getActiveDiagram();
if (diagram instanceof IBusinessProcessDiagramUIModel) {
  ...

Obtain the elements based on flow order

Once we obtained the business process diagram, then we can retrieve the elements according to the flow order:

IShapeUIModel[] shapes = ((IBusinessProcessDiagramUIModel) diagram).toShapeUIModelArrayInBusinessProcessFlow();

Walk through the collection

Now we can loop through the collection and display the flow sequence.

for (int i = 0; i < shapes.length; i++) {
  IModelElement model = shapes[i].getModelElement(); // retrieve model element from shape
  if (model != null) {
    String modelType = model.getModelType(); // retrieve model type as string
    // filter out the pool, lanes and annotations in diagram
    if (!IModelElementFactory.MODEL_TYPE_BP_POOL.equals(modelType) &&
!IModelElementFactory.MODEL_TYPE_BP_LANE.equals(modelType)&&
!IModelElementFactory.MODEL_TYPE_BP_TEXT_ANNOTATION.equals(modelType)) {
      if (i != 0) {
        sb.append(" -> "); // append separator
      }
      String name = model.getName();
      if (name != null && !"".equals(name)) {
        sb.append(model.getName()); // append model name
      } else {
        sb.append(modelType); // if the model element have no name, then append its type
      }
    }
  } else {
    sb.append(shapes[i].toString());
  }
}

Finally we display the flow sequence in message pane.

ApplicationManager.instance().getViewManager().showMessage(sb.toString());

Sample Plugin

The sample plugin attached in the article demonstrate how you can export the flow sequence of the active opened business process diagram. After you deploy the plugin into Visual Paradigm, you can then click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Trigger sample plugin

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Links

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply