List out all model elements with references
With Doc. Composer you can easily list out all model elements in your project which having particular properties defined. In this article we will demonstrate how to list out the model elements in your project which having references with other diagrams, model elements or external resources.
Sample Code
<?xml version="1.0" encoding="UTF-8"?> <ProjectBaseInitiationBlock> <IterationBlock allLevel="true"> <Conditions> <ValueChecker property="references" operator="not equals" value=""/> </Conditions> <Icon/> <Property property="name" style="@heading+"/> <ParagraphBreak/> <Text style="@heading+">References</Text> <ParagraphBreak/> <HasValueChecker property="references"> <TableBlock colWidths="25, 25, 25, 25" tableStyle="Summaries"> <TableRow> <TableCell> <Text>Name</Text> </TableCell> <TableCell> <Text>Path</Text> </TableCell> <TableCell> <Text>Description</Text> </TableCell> <TableCell> <Text>Type</Text> </TableCell> </TableRow> <ForEach property="references"> <TableRow> <TableCell> <Property property="name"/> </TableCell> <TableCell> <!-- URL, as hyperlink --> <ConditionsChecker> <Conditions type="or"> <ValueChecker operator="equals" property="type" value="URL"/> <ValueChecker operator="equals" property="type" value="File"/> <ValueChecker operator="equals" property="type" value="Folder"/> </Conditions> <Property hyperlink="true" property="path"/> </ConditionsChecker> <!-- Others --> <ConditionsChecker> <Conditions type="and"> <ValueChecker operator="not equals" property="type" value="URL"/> <ValueChecker operator="not equals" property="type" value="File"/> <ValueChecker operator="not equals" property="type" value="Folder"/> </Conditions> <Property property="path"/> </ConditionsChecker> </TableCell> <TableCell> <Property property="description" style="Description"/> </TableCell> <TableCell> <Property property="type"/> </TableCell> </TableRow> </ForEach> </TableBlock> </HasValueChecker> </IterationBlock> </ProjectBaseInitiationBlock>
How to use the sample code?
Please follow the steps below to create a template with the sample code. An explanation of code will be given in the next section.
- Open your project file which with models and references defined.
- Open Doc. Composer by select Tools > Doc. Composer from the application toolbar.
- Select Build Doc. from Scratch.
- Open Diagram Navigator and select the project root node.
- Right click on any template listed in the Template Pane and select Duplicate… from popup menu.
- In the Edit Template window, enter All Elements with Reference as the name of template.
- Replace the template code with the sample code provided in the previous section.
- Click OK.
- Now, select the project root node in Diagram Navigator, and then drag out the All Elements with References from Template Pane onto document. The list of elements and their references are shown in the document.
Explanation of sample code
The sample code demonstrate how to retrieve all elements in project which having referenced defined. The first part is to retrieve all elements in the project.
<IterationBlock allLevel="true">
With the iteration block having allLevel set to true, all model elements in the project, including the hidden model elements (those not accessible by user) will be included in the loop. Since we only want to list out those with references defined, we can put a condition in the iteration block to filter out the elements which didn’t have references.
<Conditions> <ValueChecker property="references" operator="not equals" value=""/> </Conditions>
Now all the elements in the iteration block are those with reference defined and we can start print out their details. In our sample we only want its name.
<Icon/> <Property property="name" style="@heading+"/> <ParagraphBreak/>
Next we can retrieve its reference and show it in a table.
<HasValueChecker property="references"> <TableBlock colWidths="25, 25, 25, 25" tableStyle="Summaries"> <TableRow> <TableCell> <Text>Name</Text> </TableCell> <TableCell> <Text>Path</Text> </TableCell> <TableCell> <Text>Description</Text> </TableCell> <TableCell> <Text>Type</Text> </TableCell> </TableRow> <ForEach property="references"> <TableRow> <TableCell> <Property property="name"/> </TableCell> <TableCell> <!-- URL, as hyperlink --> <ConditionsChecker> <Conditions type="or"> <ValueChecker operator="equals" property="type" value="URL"/> <ValueChecker operator="equals" property="type" value="File"/> <ValueChecker operator="equals" property="type" value="Folder"/> </Conditions> <Property hyperlink="true" property="path"/> </ConditionsChecker> <!-- Others --> <ConditionsChecker> <Conditions type="and"> <ValueChecker operator="not equals" property="type" value="URL"/> <ValueChecker operator="not equals" property="type" value="File"/> <ValueChecker operator="not equals" property="type" value="Folder"/> </Conditions> <Property property="path"/> </ConditionsChecker> </TableCell> <TableCell> <Property property="description" style="Description"/> </TableCell> <TableCell> <Property property="type"/> </TableCell> </TableRow> </ForEach> </TableBlock> </HasValueChecker>
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!