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

Hi,

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
Diagram.
I tryed the following:

DiagramPresentationElement diagram =
Application.getInstance().getProject().getActiveDiagram();
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


Petar Blagoev
 
Posts Rating:

Re: How to get all Elements included in a Diagram

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

Hi,

There are UML model elements and presentation elemets (views) in MagicDraw.
Diagram is a model element, DiagramPresentationElemet is a view of the
diagram.
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
associations.

So if you want to get the views from the diagram use:
project.getActiveDiagram().getPresentationElements();

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

Regards,
--
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
WWW: http://www.magicdraw.com

Martynas Lelevicius
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests