Number of subprocess inside diagrams


I’m trying to count the subprocesses inside a specific diagram. I don’t care if it is an “Embeddet SP”, “Reusable SP” or “Reference SP”, I want to count all of them!

I’m not able to figure out the type of a diagram element… Any hint?
This is my code so far:

       Iterator diagramIter = IProjectManager.getProject().diagramIterator();

        while (diagramIter.hasNext()) {
                          IDiagramUIModel diagram = (IDiagramUIModel);                            
                          IModels = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_BP_SUB_PROCESS);
                          lViewManager.showMessage("There are"+IModels.length+" sub processes!");
                          Iterator diagramElementIter = diagram.diagramElementIterator();                            

                           while (diagramElementIter.hasNext()) {
                               Object diagramElement =;

                               lViewManager.showMessage("Element class: "+ diagramElement.getClass().getName());
                               IDiagramElement diaEl = (IDiagramElement) diagramElement;
                               lViewManager.showMessage("Metamodelelement class: "+ diaEl.getMetaModelElement().getClass().getName());


You should use the following code fragment to count the sub-process. Feel free to contact me if you need any help.

IDiagramElement[] lDiagramElements = lDiagram.toDiagramElementArray(IBusinessProcessDiagramUIModel.SHAPETYPE_BP_SUB_PROCESS);

Best regards,