Contents

Generate PlantUML using Command Line

This is part of a series creating around PlantUML and Diagrams as Code.

  1. Authoring Plant UML files in Visual Studio Code
  2. Creating Image file from PlantUML using command line (This Post)
  3. Creating Pipeline to build and check-in Diagrams as Code
  4. Optimise the Pipeline

You may have read my previous post about using Visual Studio Code Extension to create a PlantUML files. https://www.azuredevops.tips/build-diagramsplantuml/. In this post I will cover how to bulk generate image files. This is handy if you need to bulk regenerate the diagrams without using the command line or Visual Studio Code.

Getting Started

Dependencies

I assume you have installed the required files as specified in this post https://www.azuredevops.tips/build-diagramsplantuml/ . Alternatively if you have Chcoloaty installed which can be found https://chocolatey.org/ . This is a package manager that will install the packages using command line. You need to have the right permission on your machine to install the packages.

Once Installed you can run:

1
2
3
choco install graphviz
choco install openjdk.portable
choco install nodejs

Install

The node package to carry out the image conversion. We will be using node-plantuml which has been created by Markus Hedvall.

1
npm install -g node-plantuml

Check Everything is ready

To make sure your system is ready run the following command.

1
puml testdot

/generate-plantuml-using-command-line/image1.png

This will indicate if everything is installed and configured.

Command line

I assume you have a plantUML file already if not create one for example will be enough to test it.

1
2
3
@startuml
a->b
@enduml

PNG

To create a PNG file see the command below.

1
puml generate file.puml -o file.png

The following will be created

/generate-plantuml-using-command-line/file.png

SVG

You can create SVG file

1
puml generate a.puml --svg  -o file.svg

/generate-plantuml-using-command-line/file.svg

Unicode

1
puml generate --unicode a.puml

/generate-plantuml-using-command-line/unicode.png

ASCII Art

1
puml generate --ascii a.puml

/generate-plantuml-using-command-line/ascii.png

Bulk Command

I create the following powershell script to iterate over all the folders to generate the Puml files and generate a png of the file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$dir = [string](Get-Location)
Write-Host $dir
Get-ChildItem $dir -Recurse -Filter "*.puml" |
Foreach-Object {  
    $fileWithPath = $_.Fullname         
    $png =  ("{0}\{1}.png" -f $_.DirectoryName,$_.Basename ) 
    # Write-Host $png
   $execute = "puml generate '$fileWithPath' -o '$png' "; 
   Write-Host $execute
   Invoke-Expression -Command:$execute
}