How to get all Elements included in a Diagram

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

How to get all Elements included in a Diagram

Postby Petar Blagoev » Wed Aug 29, 2007 4:43 am


I'm trying to transform Elements from one custom ClassDiagram to another. To
do that I want to collect all Class and Association Elements included in the
first Diagram and afterwords to modify/transform them into the second
I tryed the following:

DiagramPresentationElement diagram =
Collection diagramElements = diagram.getDiagram().getOwnedElement();

This call do not retrieve all Elements displayed in the diagram. What I'm
doing wrong?

Thanks in advance,

Petar Blagoev
Posts Rating:

Re: How to get all Elements included in a Diagram

Postby Martynas Lelevicius » Wed Aug 29, 2007 6:06 am


There are UML model elements and presentation elemets (views) in MagicDraw.
Diagram is a model element, DiagramPresentationElemet is a view of the
Class, Association are model elements. The diagram represents the views of
classes and associations.
Diagram as a model element does not contain elements that are represented by
it. DiagramPresentationElement contains the views of the classes and

So if you want to get the views from the diagram use:

But ff you need model elements that are represented in diagram use:
List presentationElements =
for (int i = presentationElements.size() - 1; i >= 0; --i)
PresentationElement presentationElement = (PresentationElement)
// element represented in the diagram (can be null for views that do not
represent concreate element)
Element element = presentationElement.getElement();

Martynas Lelevicius
Senior Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail : marte

Martynas Lelevicius
Posts Rating:

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest