MagicDraw 18.5 Documentation

Skip to end of metadata
Go to start of metadata

Building a Class Diagram Report

In this exercise, you will learn how to create a simple Class Diagram report. A Class Diagram report must contain the following information:

  • A class diagram's name.
  • A diagram.
  • A table that describes the class (we will call it a class description table) based on the diagram shown below.
  • The table must have the following structure:

    Class Name





    Attribute Type 1


    Attribute Type 2


    Attribute Type 3


    Attribute Type 4


  • The layout of the report should look like the example below.

Basic Class Diagram Layout

The layout of a basic class diagram on the diagram pane.


The first and most important step in creating a report is setting up the document and its layout.

  1. Open Microsoft Word.
  2. Create a table that will be used as the basic layout for a class description table.

Basic Document Layout

The layout for a class description table in a Word document containing the name of the class, the attributes, and the relationships.


As shown in the preceding figure, a diagram will appear at the top of the report followed by a class description table. Accordingly, each diagram on the Class diagrams list has a class description table describing each component in the diagram. Follow the next steps to create the document template:

Iterates through a list of diagrams.

  1. Print the diagram and its name.
  2. Get a list of class elements that are displayed in the diagram.
  3. Iterate through the list of class elements.
  4. Create a class description table for each class element in the list.

    The steps listed above contain two #foreach loops: the outer loop that iterates through a list of diagrams, and the inner loop that iterates through a list of Class elements. The list of diagrams in a MagicDraw project is represented by $Diagram.

  5. At the top of the page of the word document type:

    #foreach ($diagram in $Diagram) 
     **Codes in between ** 

    $Diagram is a list of all the diagrams in a MagicDraw project. This means that a project will be in the list if it contains more than one type of diagram. To filter out other types of diagrams, add the #if directive with a conditional statement to test whether or not $diagram is a class diagram:


  6. Next, you need to get all the elements contained in the diagram by using $report$report is a standard tool containing helpful methods such as getDiagramElements() that returns a list of elements inside a diagram.


  7. In the example above, $eList has been assigned with a list of Elements inside $diagram. Now, you need to create an inner loop that will cover the table that you created earlier, and then filter out the elements inside the diagram whose type is not Class element.



  8. Enter the information of the class in the table by calling its attributes, etc.:

    The example above shows that the Class Name and Documentation values are obtained by referencing the name and documentation attributes of $e


  9. Use the #forrow directive as the attribute to print rows of the class attribute type ($ and the class attribute name ($

  10. Save the file as Rich Text Format. Open MagicDraw and draw a simple class diagram.

    A Simple Class Diagram

    A simple class diagram.

  11. Add the template to Report Wizard, and generate a class diagram report using this template. The following figure shows the result of the generated report.

    A Generated Report
    The generated report of the class diagram in the Word document



On this page



A class diagram is a diagram in which the primary symbols in the contents area are class symbols.


More information about working with report templates using Report Wizard

To learn more about working with report templates, visit the following pages:

To create a report with the Actor, Use Cases, and diagram image names


  • No labels