- Step 1: Create the virtual document with a script
- Step 2: Generate the document from the virtual document
Document generation is important in most organisations that work with Enterprise Architect. Storing information in the model is good, but most stakeholders still require documents.
Documents are using as a tool for validation, as a work order, or just to give you an overview of a specific set of thing in the model. The main advantages of a document versus a model is that it has a limited scope and a linear order. You can read a document from start to finish, whereas you cannot do that with a model. Documents are, and will always be an important tool in developing applications.
Enterprise Architect comes with a sophisticated document generator that has seen great improvements in the last versions (v10, v11, v12). You also get a standard set of document templates that will quickly generate a document for a part of your model.
The problems arise however the moment you try to do something a bit more sophisticated with the document templates. Get information from different packages, use different templates for the same (set of) elements, etc… You will quickly realize that the approach of having one large template that generates the whole document is not useful for real-world document requirements.
Luckily EA has an alternative to the single template approach: Virtual Documents
I’ve put together an example model and an MDG to demonstrate this approach. The MDG contains all scripts, templates and SQL Searches to generate a decent Use Case Document.
After you open the Hotellio.eap file, right click on the Reservations use case diagram and choose Create Use Case Document
Then select the package to store the virtual document in and fill in the version.
Finally select the «master document» package and press F8 so start the document generation. Make sure to select the correct cover page and style sheet
Virtual Documents are used to define the contents of a document as a set of individual sections, each with its own source and template.
There are two types of elements that are used for virtual documents
- Master Document
Represents the document to be printed. You can give it some parameters that can be used in the document itself such as title, Version, Status, etc…
- Model Document
Represents a section in your document. The model document gets an RTFTemplate, and you have to define a source for this section. The source tell us which element(s) from the model should be used in this section. There are two ways to define the source. You can either drag one or more packages onto it, or you can fill in the Model Search and Search Term.
Master Documents get stored in the model as stereotyped packages and they contain stereotypes classes to represent the Model Documents
In the project browser this looks like this.
The Master Documents get the stereotype «master document» They contain tagged values to store things like ReportAlias, ReportTitle. Event though you can assign an RTF template to the master document this seems to be pointless since it gets ignored when printing a document.
Model Documents get the stereotype «model document». The links to the packages that serve as the source for a model document are created by dragging the package from the project browser onto the model document. This creates an attribute that maintains the link to the package.
Tagged values are used to indicate the template to use, the model search to use, and the search value to use on that search.
This mechanism of model documents allows you to very precisely control what will be printed in the document.
RTF templates are stored in the Resources section of your model. In order to see and manage them enable the resources view using View|Resources
Templates for document that have a package as source can start from the package tag and access all element, diagram etc.. in that package.
If your source is an SQL search that returns elements your template content can be placed in the element section
The SQL search I use to select a single element based on its GUID this following:
When you select the Master Document you can open up the document generation dialog by pressing F8
Here you can set the cover page, table of contents, and the style sheet to use.
Side note: Invest in the style sheet. It will save you time and frustration afterwards. It is difficult, and awkward to set styles using the RTF editor, but if you do it once in the stylesheet you don’t have to to it over and over again in each template. Also make sure to create your own “normal” style and call it “my normal” or something like that. Use this instead of the regular “normal”. There seems to be some weird behavior associated by the “normal” style, so I learned it’s best not to use it at all.
Then press generate, and the document generator will create one big document containing
- The cover page
- The table of contents page
- All model documents in the order they appear in the project browser.
If you are not happy with the content of the document, or the order of the model documents then you can change them in EA and re-print the document.
One of the advantages is that the content of the document is stored in EA. So after a revision of the model you can print exactly the same content again and compare it with the previous version.
Automatically generate virtual documents
Using virtual documents like that is all nice and good, but it still requires quite a lot of work to assemble the virtual document itself. For a somewhat realistic document you easily end up with tens of model documents, all pointing to different element or packages, and different template.
And you have to repeat that process for all the different documents you want to generate.
Doing the same thing over and over again is exactly what computers are build for. Instead of having to assemble the virtual document manually we will write a little script to do it for us.
The first thing well need to do is to make the Master Document package. This VBScript function does that for us.
Then we need to make the Model Documents.To make one with a Package as source we use this function
To make one with an SQL Search as source we use this function
The the last script we is one to actually use these functions in order to create the virtual document. In the example provided I’ve split the script in two parts. One part that remains in the library, and one script that is put in the Diagram Group so we can call it from a diagram directly.
The script in the Diagram Group takes care of getting the user input
The script in the library will use the functions mentioned above to start building the virtual document