How to retrieve a diagram in your project using Open API

Visual Paradigm’s Open API allow user to access the model data in your project in programmatic way by creating plugin. With Open API you can create new diagram or model elements to your project, also retrieve the diagram or model elements form your project and manipulate it. To retrieve a diagram from your project, we first obtain the reference of your current opening project from the ApplicationManager.

IProject project = ApplicationManager.instance().getProjectManager().getProject();

After you obtained the project, you can use to toDiagramArray method to retrieve the reference for all the diagrams in your project into an array, regarding to their model structure.

IDiagramUIModel[] diagrams = project.toDiagramArray();

The method toDiagramArray will return null if your project didn’t contain any diagram. As long as the array is not null you can then loop through it to access the diagram one by one. You can use the instanceof operator to see which type of diagram it is, and use the getName() method to obtain the name of the diagram to determine is it the diagram you looking for.

// assume we looking for a class diagram call “Hello World”
if (diagram instanceof IClassDiagramUIModel && "Hello World".equals(diagram.getName())) {
  ... // do what you want with this diagram

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply