Publisher and Web Interface > Publisher > Developing document definitions > Overview of developing document definitions (Publisher) > Worked example: extracting diagrams and their items (Publisher)
  
Worked example: extracting diagrams and their items (Publisher)
This is one of five worked examples that relate to developing document structures:
Worked example: extracting items through model item types
Worked example: extracting items through child roles and child types
Worked example: extracting items through extended model item types (stereotypes)
Worked example: extracting diagrams and their items
Worked example: extracting specific items
This worked example demonstrates how to extract diagrams from a model through a model item type, and then how to develop that model item type to extract items that appear on the extracted diagrams. This example uses the Word output format.
In this worked example, we create a document definition that extracts the following information from a model:
All the Class Diagrams in a model, including an image of the diagram.
For each Class Diagram: all the Classes that appear on the diagram in a tabular format that shows the Name, Last Author and Last Changed Date properties of each Class.
The example uses the Traffic Lights model that resides in the provided Examples database. The Traffic Lights model has two Class Diagrams:
The Class Diagram class diagram contains two Classes named Controller and Lights.
The Dependencies class diagram does not contain any Classes.
Defining the extraction of Class Diagrams
In this example, we start by opening the Traffic Lights model in Modeler, and creating a new empty Document Definition.
We ensure that Publisher is showing all the panes required to define a Document Definition by clicking the Full Editor Layout toolbar button.
We want our generated document to have a heading for each Class Diagram in the model and we want each heading to be followed by an image of the Class Diagram; so we need to add a Class Diagram model item type to our document structure. Adding a Class Diagram model item type to our document will extract all Class Diagrams from the model.
To do this, we select the Body icon in the document structure, click the Add Modeler Diagram Section button, and then select the Class Diagram type.
We generate the document and the following text appears in the Word document.
We want to make the following changes:
We want to change the first heading from 'CLASSDIAGRAM' to 'CLASS DIAGRAMS IN THE MODEL'.
We want only the Class Diagram image to be generated; we do not want to generate the Name, FullScopedName, Description and DynamicUmlClassName properties.
We change the first heading from 'CLASSDIAGRAM' to 'CLASS DIAGRAMS IN THE MODEL' by selecting the Class Diagram item in the document structure, and then in the Properties pane changing the Title Text property from 'ClassDiagram' to 'Class Diagrams in the model'.
In the Properties pane, we can see that the Name, FullScopedName, Description, DynamicUmlClassName and EMFPlusOnly properties are extracted.
We remove the Name, FullScopedName, Description and DynamicUmlClassName properties by selecting each property in turn and clicking the Delete Item button.
We now only extract the EMFPlusOnly property, which is the diagram image.
We generate the document again and the text is now as we want it: the CLASSDIAGRAM heading now states CLASS DIAGRAMS IN THE MODEL, and only the image of the diagram is extracted through the EMFPlusOnly property.
Defining the extraction of Classes that appear on the Class Diagrams
After the diagram image that is generated for each Class Diagram, we want to generate a table that lists each Class that appears on the diagram. For each Class, we want to include its Name, Last Author and Last Changed Date properties.
To do this we extend the definition of the Class Diagram item that we created in the document structure.
We want to extract Classes that appear on the diagram, and we do this by extracting items that are related to the owning Class Diagram through the automation interface role (association) that is named Used Dictionary Item.
Tip: The Used Dictionary Item role extracts all items that appear on a diagram, or in the case of Text Diagrams, all items that are referenced through Model Object References.
We select the 'Class Diagrams in the Model' item, click the Add Modeler Child Role Section button, and then select the Used Dictionary Item child role.
The icon indicates that the Used Dictionary Item is a child role (association).
The Used Dictionary Item role extracts all the items used on the diagram, but we only want to extract Class items. To extract only Class items, we must add a child Class model item type to the Used Dictionary Item role, that is, we want to extract Class items that are linked to the Class Diagram through the Used Dictionary Item role.
In the document structure, we select the Used Dictionary Item role, click the Add Modeler Child Type Section button, and then select the Class child type.
We want to generate the Class properties in a table, so we select the Class child type and set the Organize As Sections/Table property to In Table.
We want the table to be named Classes on Diagram, so we change the Title Text to Classes on Diagram. Note that when the Organize As Sections/Table property is set to In Table, the title of the table appears in the List of Tables section of the document.
Finally, we change the extracted properties to Name, Last Author and Last Change Date.
We save the changes and then generate the document. The Word document includes the following text.
After the first Class Diagram there is now a table that shows the Name, Last Author and Last Change Date properties of each Class that appears on the diagram.
In this worked example, we have demonstrated how to extract diagrams through a model item type, and then how to extract items that appear on those extracted diagrams.