Output all relationships within a diagram into document
Doc. Composer provides a highly customizable way to output project content into document. It allows you perform query and output the content in diagram scope, or in the model repository scope. In this article we will show you how to output all relationships in a specific diagram into document.
- Go to Tools > Doc. Composer.
- Select Build Doc. from Scratch.
- Select your diagram in Diagram Navigator.
- Right click on any template in Template pane and select Duplicate from popup menu.
- Name the template as Relationships Only (Diagram Scope).
- Replace the content of the template as follow.
<?xml version="1.0" encoding="UTF-8"?> <DiagramBaseInitiationBlock> <Property anchorMark="true" property="name" style="@heading+"/> <ParagraphBreak/> <Image alignment="center" keepWithPreviousInPDF="true"/> <ParagraphBreak/> <IterationBlock> <Icon/> <Property property="name" style="@heading+"/> <ParagraphBreak/> <ForEachRelationshipConditionChecker> <TableBlock tableStyle="summaries"> <TableRow> <TableCell><Text>Relationship</Text></TableCell> <TableCell><Text>Details</Text></TableCell> </TableRow> <ForEachRelationship direction="to"> <TableRow> <TableCell> <Icon/> <ValueChecker property="name" value="unnamed"> <Property property="modelType"/> </ValueChecker> <ValueChecker property="name" operator="not equals" value="unnamed"> <Property property="name"/> </ValueChecker> </TableCell> <TableCell> <Text>From: </Text> <FromElement> <Icon/> <Property property="name"/> </FromElement> </TableCell> </TableRow> </ForEachRelationship> <ForEachRelationship direction="from"> <TableRow> <TableCell> <Icon/> <ValueChecker property="name" value="unnamed"> <Property property="modelType"/> </ValueChecker> <ValueChecker property="name" operator="not equals" value="unnamed"> <Property property="name"/> </ValueChecker> </TableCell> <TableCell> <Text>To: </Text> <ToElement> <Icon/> <Property property="name"/> </ToElement> </TableCell> </TableRow> </ForEachRelationship> </TableBlock> </ForEachRelationshipConditionChecker> </IterationBlock> </DiagramBaseInitiationBlock>
- Press Save button and close the Edit Template dialog.
- Drag the Relationships Only (Diagram Scope) template into document editor.
Now all relationships in the selected diagram will being listed out, organized according to the model elements.
Explanation of the template
The template perform the query on diagram scope, and it first output the image of the diagram into document.
<?xml version="1.0" encoding="UTF-8"?> <DiagramBaseInitiationBlock> <Property anchorMark="true" property="name" style="@heading+"/> <ParagraphBreak/> <Image alignment="center" keepWithPreviousInPDF="true"/> <ParagraphBreak/>
Then it goes into the loop to walk through all elements in diagram and output its name & icon.
<IterationBlock> <Icon/> <Property property="name" style="@heading+"/> <ParagraphBreak/>
Next use the ForEachRelationshipConditionChecker to see is the element involved in any relationships. If yes then it move on to output the table for listing out the relationships.
<ForEachRelationshipConditionChecker> <TableBlock tableStyle="summaries"> <TableRow> <TableCell><Text>Relationship</Text></TableCell> <TableCell><Text>Details</Text></TableCell> </TableRow>
Now we query the relationships of the shape using the ForEachRelationship loop. We filter out the relationships where the shape we working on is the “to” end in the relationship (direction=”to”).
<ForEachRelationship direction="to">
Then we create a table row to output its details, including its icon, name or model type (showing the type if it is unnamed), and also the most important part, the from end model element’s name.
<TableRow> <TableCell> <Icon/> <ValueChecker property="name" value="unnamed"> <Property property="modelType"/> </ValueChecker> <ValueChecker property="name" operator="not equals" value="unnamed"> <Property property="name"/> </ValueChecker> </TableCell> <TableCell> <Text>From: </Text> <FromElement> <Icon/> <Property property="name"/> </FromElement> </TableCell> </TableRow>
Next we repeat this section but swapping the From and To so that we can also report the relationships which we are on the “from” end.
<ForEachRelationship direction="from"> <TableRow> <TableCell> <Icon/> <ValueChecker property="name" value="unnamed"> <Property property="modelType"/> </ValueChecker> <ValueChecker property="name" operator="not equals" value="unnamed"> <Property property="name"/> </ValueChecker> </TableCell> <TableCell> <Text>To: </Text> <ToElement> <Icon/> <Property property="name"/> </ToElement> </TableCell> </TableRow> </ForEachRelationship>
Please note that since this template is query on diagram scope. Only the relationships on this diagram will be outputted. Relationships on element exist on other diagrams will not be covered in the reporting scope.
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!