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?
Summaries:
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"?>
<DiagramBaseInitiationBlock>
<Text>Diagram: </Text><Property property="name"/>
<ParagraphBreak/>
<!-- check any Elements drawn in this diagram -->
<IterationBlockConditionChecker>
<Text>Elements: </Text>
<!-- foreach the elements and print their name:modelType -->
<IterationBlock ignoreLastSeparator="true">
<Property property="name"/><Text>:</Text><Property property="modelType"/>
<Text>, </Text>
</IterationBlock>
<ParagraphBreak/>
</IterationBlockConditionChecker>
<!-- check any Elements contains sub-diagram -->
<IterationBlockConditionChecker>
<Conditions>
<HasSubDiagramChecker/>
</Conditions>
<Text>Sub Diagrams: </Text>
<!-- foreach the elements, which has sub-diagrams -->
<IterationBlock>
<Conditions>
<HasSubDiagramChecker/>
</Conditions>
<!-- 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>
</ForEachSubDiagram>
</IterationBlock>
<ParagraphBreak/>
</IterationBlockConditionChecker>
</DiagramBaseInitiationBlock>
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
}
}
}
}
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.