How to retrieve comments of entities with openAPI


I am currently wiritng an API scripts which retrieves entities, columns, stereotypes and comments of a diagram but I am stuck in retrieving the comments of an entity (IDBTableUIModel). Could you please suggest how to do it.

The Entity has a “SQL Mapping” comment with a SQL in its description. That is the info I like to get

I could not find a method which gets the comments (IComment Array) of IModelElement

public class ERDAction implements VPActionController {
public void performAction(VPAction arg0) {
IProject project = ApplicationManager.instance().getProjectManager().getProject();
IDiagramUIModel[] diagrams = project.toDiagramArray();
if (diagrams != null) {
for (IDiagramUIModel diagram : diagrams) {
if (diagram instanceof IERDiagramUIModel && “AnyDiagram”.equals(diagram.getName())) {
IDiagramUIModelComment[] comments = diagram.toCommentArray();
if (comments != null) {
// Diagra comment is OK
for (IDiagramUIModelComment comment : comments) {
ApplicationManager.instance().getViewManager().showMessage(" ->COMMENTS…" + comment.getAuthor());

				-- Get Entities
				if (elements != null) {
					for (IDiagramElement element : elements) {

						IModelElement modElement = element.getModelElement();

						if (element instanceof IDBTableUIModel) {
						// Entitiy Found

							//Retrieve Table StereoType 
							ApplicationManager.instance().getViewManager().showMessage("	->Has StereoType:" + element.getModelElement().hasStereotype("coloumn1_"));
							ApplicationManager.instance().getViewManager().showMessage("	->Has StereoType:" + element.getModelElement().hasStereotype("test"));
							//Get all stereoTypes of entity
							IStereotype[] stereotypes = element.getModelElement().toStereotypeModelArray();
							if (stereotypes != null) {
								for (IStereotype stereotype : stereotypes) {
									ApplicationManager.instance().getViewManager().showMessage("	->got StereoType " + stereotype.getName() + " for table " + modElement.getName());
							// Get columns
							IModelElement[] tableElements = element.getModelElement().toChildArray();

							if (tableElements != null) {

								for (IModelElement tableelement : tableElements) {
									ApplicationManager.instance().getViewManager().showMessage("	-> table Element " + tableelement.getName());



Thanks for your gıidance is advance

Best Regards

Hi seyhmus,

Thank you for your inquiry. Your question has been forwarded to our engineers. I will let you know when there is any update.

Best regards,
Jick Yeung

Hi Seyhmus,

Since not all model types support the comments’ property, functions such as toCommentArray() etc… are not supported by IModelElement directly.

You may:

A. Cast your model element to IDBTable (model element of an ERD entity), which supports the functions:
public void addComment(IComment comment);
public void removeComment(IComment comment);
public IComment getCommentByIndex(int index);
public void removeCommentByIndex(int index);
public int commentCount();
public Iterator commentIterator();
public IComment[] toCommentArray();

B. Use:
IModelElement.getModelPropertyByName(IDBTable.PROP_COMMENTS) : IModelProperty
IModelProperty.getValueAsModelCollection() : IModelElement[] <----- this array contains the IComment

PS: the constants PROP_COMMENT is supported in any model type that supports comments property (e.g. IClass.PROP_COMMENTS).

Best regards,
Jick Yeung

1 Like

Hello Jick, Thanks a lot for quick solution. Both suggestions worked. This saved me a lot time :pray:

My pleasure. :slight_smile: