Generate text document with doc composer


I’m trying to export diagram data as text file.
I’d like to use Doc Composer to use XML templates.
I saw this tutorial (, but how to generate text file from IReportDiagramUIModel ?
Only image export allowed?

Thanks in advance.


Interesting question!

Just so I fully understand your intention: the main goal is to export the data in your diagram(s) as a text file, that’s it, right?

I think your best option is to set up a document and then export that as a Word document. After that you should be able to load that into Word or Open Office writer or maybe even the online Office tools, and then export your document into plain text format.

That should be a lot easier than having to rely on the OpenAPI.

Thanks for your replay.
The problem is that I have a lot documents to export so i would take a lot of time to do that manually each time.
I could create my own custom templates and replace values in it at export but this need to develop the template engine for it. It would be nice if it was handled by OpenAPI.

Hmm, not sure how you’d best proceed here. There is the DocumentationManager which provides methods to generate things (for example GenerateWordDoc()) but that would still require a template to use.

I guess it depends on how you’re planning to perform the export. One diagram at a time or would your template contain several?

I’d like to generate one file by diagram but with some child diagrams data too.
I want to generate asciidoc/markdown documents.

Like that?

use <Text>...</Text> to generate static text
use <Property property=... /> to generate text from your diagram or element
use <IterationBlock> to retrieve elements from your diagram
use <ForEachSubDiagram> to retrieve sub diagrams from your element

<?xml version="1.0" encoding="UTF-8"?>
	<Text>Diagram: </Text><Property property="name"/>
	<!-- check any Elements drawn in this diagram -->
		<Text>Elements: </Text>
		<!-- foreach the elements and print their name:modelType -->
		<IterationBlock ignoreLastSeparator="true">
			<Property property="name"/><Text>:</Text><Property property="modelType"/>
			<Text>, </Text>
	<!-- check any Elements contains sub-diagram -->
		<Text>Sub Diagrams: </Text>
		<!-- foreach the elements, which has sub-diagrams -->
			<!-- foreach the sub-diagrams from an element, and print their name:diagramType -->
			<ForEachSubDiagram ignoreLastSeparator="true">
				<Property property="name"/><Text>:</Text><Property property="type"/>
				<Text>, </Text>
1 Like

Thanks for your reply.
But how do you export it?
I only see export in word or pdf.

Yeah, you can’t directly export to a text file. But you could easily export in Word and then convert the Word document to text.

Sorry, if use Doc. Composer to generate content, the content only can be exported to WORD, PDF, or HTML.
You have to parse the HTML (or WORD’s xml), or Copy and Paste from the WORD/PDF file).

So, the better solution should be implement a plugin to generate your text.
Let me try to show you some code segment:

IProject project = ApplicationManager.instance().getProjectManager().getProject(); // your diagrams can be get from the IProject
IDiagramUIModel[] diagrams = project.toDiagramArray(); // all diagrams of your project
for (IDiagramUIModel diagram : diagrams) {
  // you may filter the diagram by diagram type:  #getType():String

   IDiagramElement[] diagramElements = diagram.toDiagramElementArray(); // get the diagram elements which is showing on this diagram
   if (diagramElements != null) {
      for (IDiagramElement diagramElement : diagramElements) {
         IModelElement modelElement = diagramElement.getModelElement(); // get the model element which is represented by this diagram element
         if (modelElement != null) {
            // you may filter the model element by model type:  #getModelType():String

            IDiagramUIModel[] lSubDiagrams = modelElement.toSubDiagramArray(); // get the sub diagrams of your model element


If you don’t know how to implement a plugin, you may download a sample from, such as:

Open its plugin.xml, you will find there is an <action ...> with an <actionController class='...'
The above sample code should be implemented in an ActionController class.
You can modify that plugin.xml to be your plugin. (e.g. provide your label, icon into the <action>, the action will be shown as a button in Ribbon.

About how to make your plugin works in VP, please reference it:

1 Like