Hiding class attributes using Open API

Visual Paradigm Open API provide Java programming interface for manipulate diagrams and models within the project. In this article we will show you how to hide out attribute from class shape in class diagram. Suppose we would like to hide out the name attribute from Customer class in current opening diagram:

Retrieve class shapes form diagram

First we have to retrieve the class shapes form current opening diagram.

// Retrieve active diagram, and proceed if it is a class diagram
IDiagramUIModel currentDiagram = ApplicationManager.instance().getDiagramManager().getActiveDiagram();
if (currentDiagram instanceof IClassDiagramUIModel) {
  IClassDiagramUIModel classDiagram = (IClassDiagramUIModel) currentDiagram;
  // Retrieve all class shape in the diagram
  IDiagramElement[] diagramElements = classDiagram.toDiagramElementArray(IClassDiagramUIModel.SHAPETYPE_CLASS);
  if (diagramElements.length > 0) {
    // Walk through the class shapes
    for (int i = 0; i < diagramElements.length; i++) {
      IClassUIModel classShape = (IClassUIModel) diagramElements[i];

Obtain class model from class shape

Once we retrieved the class shapes we walk through them one by one to obtain the class model, and see is it the Customer class we looking for.

// Retrieve class model from class shape 
IClass classModel = (IClass) diagramElements[i].getModelElement();
// Retrieve attributes if the class named "Customer"
if ("Customer".equals(classModel.getName())) {

Hide out the specified attribute

When the Customer class was found, retrieve the attributes from it and found out the name attribute.

IAttribute[] attributes = classModel.toAttributeArray();
for (int j = 0; j < attributes.length; j++) { 
  // Walk through all attributes to see is there any name named as "name"
  if ("name".equals(attributes[j].getName())) {

When the name attribute was found, we add it to hidden attribute model and set the class to customized attribute display mode.

// Hide away to attribute which named as "name"
classShape.setHiddenAttributeModels(new IAttribute[] {attributes[j]});

Sample Plugin

The sample plugin attached demonstrate how to hide out the name attribute from Customer class. After you deploy the plugin into Visual Paradigm you can open the class diagram and press the Hide Attribute button in Plugin tab to hide out the attribute.

Execute sample plugin to hide out the name attribute

Execute sample plugin to hide out the name attribute

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

2 replies
  1. ShelLuser says:

    Visual Paradigm goes “open source”, who would have thought 😉

    More seriously: I’ve been looking into the OpenAPI a few times already and this example might be just the thing I need to get my fingers behind getting a project of some sort started. Thanks for this!

  2. VisualParadigm says:

    Hi ShelLuser,

    Thank you for your post. With our OpenAPI you can write your program to access a model as well as to execute some of our application’s functions. You can also add buttons and menus to our GUI to involve your program. For more details, please visit:

    Plug-in User’s Guide:

    Plug-in API:

    Plug-in Samples:

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply