Generate Document for each Business Process Diagram in Project using Open API
Doc. Composer is a build-in document builder in Visual Paradigm which allows user create professional looks document with fully customizable XML templates. With the Build from Scratch mode user can create customized XML template and drag & drop it into document editor for rendering documents. This process can be automated using Open API. In this document we will demonstrate how create plugin to automatic publish all business process diagrams in your project to Word document using your specified XML template.
Since the implementation of user interface of the sample plugin is not focus in this topic, therefore they will not be explained in details. We will focus on the section related to generating documents.
Prepare Default Content Block
First we have to prepare the default content block for holding the template we going to use.
// Retrieve default content block public static IRDOOTemplate getBpdReportTemplate() { // Retrieve Doc. Composer in project IReportDiagramUIModel lReportDiagram = getBpdReport(); if (lReportDiagram == null) { return null; } IProject lProject = ApplicationManager.instance().getProjectManager().getProject(); IReportDiagramDetails lDetails = (IReportDiagramDetails) lProject.getModelElementByAddress(lReportDiagram.getGenericXMLElementAddress()); return lDetails.getRDOOTemplateByName(TEMPLATE_NAME); }
If it not exist then we create one.
// Create content block private boolean prepareReportTemplate() { IBusinessProcessDiagramUIModel[] lBpds = BpdsReportGenerator.collectBpds(); if (lBpds.length == 0) { ApplicationManager.instance().getViewManager().showMessageDialog( BpdReportTemplateDialog.this.getComponent(), "Please open the project contains your BPD(s).", "BPD not found", JOptionPane.ERROR_MESSAGE ); return false; } // Create document template model form user specified template XML BpdsReportGenerator.createBpdReportTemplate(_templateXmlField.getText(), lBpds, BpdReportTemplateDialog.this.getComponent()); IRDOOTemplate lTemplate = BpdsReportGenerator.getBpdReportTemplate(); { if (lTemplate != null) { _templateXmlField.setText(lTemplate.getTemplateURI()); } } return lTemplate != null; }
Specify Template for Content Block
Once the default content block is ready we can then set user specified template to content block.
//Use user specified template in content block lTemplate.setTemplateURI(_templateXmlField.getText());
Generate Document for each BPD
Finally we walk through all BPDs in project to set the diagram ID into content block, and then output it to Word files.
for (String lBpdId : lBpdIds) { lIndex++; _progressBar.setString("Generating... ("+lIndex+" of "+lBpdIds.length+")"); { // Retrieve the template model user specified, and specify the diagram ID into template IRDOOTemplate lTemplate = BpdsReportGenerator.getBpdReportTemplate(); lTemplate.setSourceId(lBpdId); } // Generate document to Word file. File lOutputFile = new File(lOutputDir, lBpdNames[lIndex]+".docx"); lDocumentationManager.generateDocComposerWord(lReportDiagram, lOutputFile, BpdReportTemplateDialog.this._panel); ApplicationManager.instance().getViewManager().showMessage( "["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"] " + "Generated: " + lOutputFile.getAbsolutePath(), "com.vp.plugin.sample.generatereportcomposer" ); _progressBar.setValue(lIndex+1); _progressBar.setString("Generating... ("+(lIndex+1)+" of "+lBpdIds.length+")"); } _progressBar.setString("Done"); }
Sample plugin
The sample plugin attached demonstrate how to publish all BPDs in your project to Word document. After you deploy the plugin into Visual Paradigm you can press the plugin button to bring up the dialog.
In the dialog you have to specify the URL of the template you would like use as well as the output folder. You can obtain the URL of your temple in the following way.
- Go to Tools > Composer > Manage Template XML…
- Select Diagram Type at top left of the Manage Template XML.
- Select Business Process Diagram and then choose the template under Template pane.
- Select the URI and press Ctrl + C to copy it.
- Open the Generate BPD Report(s) dialog and press Ctrl + V to paste the Template URI field.
Once everything being specified you can press the Generate Report(s) button to generate the document.
Download sample plugin
You can click this link to download the sample plugin.
- Please note that this plugin only works for Visual Paradigm client version 15.0 build 20180451fi or later release.
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!