How to output class members to document which only show in diagram

Visual Paradigm support reuse models in different diagrams. The same element can have different presentations, or even showing different details on different diagrams. i.e., a class can show different set of attributes in different diagrams subject to the context. In this article we will show you how to create document for your classes which only showing the attributes which presented in your diagram.

In our example we got a class diagram where the Display Monitor class having the Color attribute being set to hidden.

Class with hidden attribute

Class with hidden attribute

To output the classes and attributes displayed on diagram:

  1. Go to Tools > Doc. Composer.

    Open Doc. Composer

    Open Doc. Composer

  2. Select Build Doc. From Scratch.

    Select Build Doc. from Scratch

    Select Build Doc. from Scratch

  3. Select the class diagram in Diagram Navigator tree.

    Select class diagram in Diagram Navigator

    Select class diagram in Diagram Navigator

  4. Right click on any template in Template pane and select Duplicate form popup menu.

    Duplicate any template

    Duplicate any template

  5. Name the template as All classes and on-screen attributes.

    Name it as All classes and on-screen attributes

    Name it as All classes and on-screen attributes

  6. Replace the content of the template as follow.
    <?xml version="1.0" encoding="UTF-8"?>
    <DiagramBaseInitiationBlock>
      <IterationBlock ignoreLastSeparator="false" modelType="Class">
    
        <Icon/>
        <Property property="name" style="@heading+"/>
        <ParagraphBreak/>			
        
        <!-- Attributes (Summary) -->
        <HasChildElementChecker modelType="Attribute" filterHidden="true">
          <Text style="@heading+">Attributes Summary</Text>
          <ParagraphBreak/>
        
          <TableBlock colWidths="20, 80" tableStyle="Summaries">
            <TableRow>
              <TableCell>
                <Text>Name</Text>
              </TableCell>
              <TableCell>
                <Text>Description</Text>
              </TableCell>
            </TableRow>    
            <IterationBlock modelType="Attribute" filterHidden="true">
              <TableRow>
                <TableCell>
                  <Icon/>
                  <Property property="name"/>
                </TableCell>
                <TableCell>
                  <Property property="description" style="Description"/>
                </TableCell>
              </TableRow>
            </IterationBlock>
          </TableBlock>
        </HasChildElementChecker>
      </IterationBlock>
    </DiagramBaseInitiationBlock>
  7. Press Save button and close the Edit Template dialog.
  8. Drag the All classes and on-screen attributes template into document editor.

    Drag the template into document

    Drag the template into document

Now the classes and the non-hidden attributes are being output into document.

Only the attributes on diagram being output to document

Only the attributes on diagram being output to document

Explanation of the template

Our template is created under Class Diagram and therefore default it already in diagram scope. The first loop in the template will be loop through all the classes in the diagram (ignore other elements).

<?xml version="1.0" encoding="UTF-8"?>
<DiagramBaseInitiationBlock>
  <IterationBlock ignoreLastSeparator="false" modelType="Class">

We then first printout its icon and name in header style.

<Icon/>
<Property property="name" style="@heading+"/>
<ParagraphBreak/>

Next we detect is the classes contain any attributes. If the class contain attributes we will then go into the block to printout the table header. Note that since we only want to printout the attributes which showing on diagram, to do this we add the special argument filterHidden=true into the value checker.

<!-- Attributes (Summary) -->
<HasChildElementChecker modelType="Attribute" filterHidden="true">
  <Text style="@heading+">Attributes Summary</Text>
  <ParagraphBreak/>

  <TableBlock colWidths="20, 80" tableStyle="Summaries">
    <TableRow>
      <TableCell>
        <Text>Name</Text>
      </TableCell>
      <TableCell>
        <Text>Description</Text>
      </TableCell>
    </TableRow>

Now we create the second loop for printout the attributes from the classes. Again we put the filterHidden=true into the loop to make sure it only go through the attributes which showing on diagram.

<IterationBlock modelType="Attribute" filterHidden="true">
  <TableRow>
    <TableCell>
      <Icon/>
      <Property property="name"/>
    </TableCell>
    <TableCell>
      <Property property="description" style="Description"/>
    </TableCell>
  </TableRow>
</IterationBlock>

Remarks

The filterHidden argument supported since version 16.0 build 20190890bc.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply