How to use the command "plantuml" (with examples)

How to use the command "plantuml" (with examples)

The plantuml command is a tool that allows you to create UML diagrams using a plain text language and then render them in various formats, such as PNG, PDF, SVG, or TXT. This command is useful for software developers, system architects, and anyone who needs to create visual representations of their code or systems.

Use case 1: Render diagrams to default format (PNG)

Code:

plantuml diagram1.puml diagram2.puml

Motivation: You can use this command to render multiple UML diagrams stored as PlantUML files (files with a .puml extension) into the default format, which is PNG. This is useful when you have multiple diagrams that you want to render at once.

Explanation:

  • diagram1.puml and diagram2.puml: The names of the PlantUML files that contain the diagrams you want to render.

Example output: The command will generate PNG files for both diagrams: diagram1.png and diagram2.png.

Use case 2: Render a diagram in given format

Code:

plantuml -t format diagram.puml

Motivation: By using this command, you can specify the desired output format for the rendered diagram. This allows you to generate diagrams in formats other than the default PNG, such as PDF, SVG, or even plain text.

Explanation:

  • -t format: Specifies the output format for the rendered diagram. Replace format with the desired format, such as png, pdf, svg, or txt.
  • diagram.puml: The name of the PlantUML file that contains the diagram you want to render.

Example output: The command will generate a diagram in the specified format, such as diagram.pdf or diagram.svg.

Use case 3: Render all diagrams of a directory

Code:

plantuml path/to/diagrams

Motivation: Sometimes you may have a directory that contains multiple PlantUML files, each representing a separate diagram. Instead of rendering each file individually, you can use this command to render all the diagrams in the given directory.

Explanation:

  • path/to/diagrams: The path to the directory containing the PlantUML files.

Example output: The command will generate the corresponding output files for each diagram in the directory, considering the default format (PNG). For example, if the directory contains diagram1.puml and diagram2.puml, the command will generate diagram1.png and diagram2.png.

Use case 4: Render a diagram to the output directory

Code:

plantuml -o path/to/output diagram.puml

Motivation: In some cases, you may want to specify a different output directory for the rendered diagram files. This command allows you to do that by specifying the desired output directory.

Explanation:

  • -o path/to/output: Specifies the output directory where the rendered diagram files will be saved.
  • diagram.puml: The name of the PlantUML file that contains the diagram you want to render.

Example output: The command will generate the rendered diagram file in the specified output directory, using the default format (PNG). For example, if the output directory is output and the diagram file is diagram.puml, the command will generate output/diagram.png.

Use case 5: Render a diagram with the configuration file

Code:

plantuml -config config.cfg diagram.puml

Motivation: The plantuml command allows you to use a configuration file to define custom settings for rendering the diagrams. By using this command, you can specify the path to the configuration file that you want to use.

Explanation:

  • -config config.cfg: Specifies the path to the configuration file that contains the custom settings.
  • diagram.puml: The name of the PlantUML file that contains the diagram you want to render.

Example output: The command will use the custom settings defined in the configuration file to render the diagram. The output will be generated based on the specified settings.

Use case 6: Display help

Code:

plantuml -help

Motivation: If you need information about the usage and available options of the plantuml command, you can use this command to display the help message.

Example output: The command will display the help message, which provides information on how to use the command and its available options. This message usually includes a brief description, usage examples, and explanations of each option.

Related Posts

How to use the command qmmp (with examples)

How to use the command qmmp (with examples)

This article will provide examples of how to use the qmmp command, which is an audio player.

Read More
How to use the command 'spatial' (with examples)

How to use the command 'spatial' (with examples)

The ‘spatial’ command is a set of commands for managing and developing SpatialOS projects.

Read More
How to use the command pio boards (with examples)

How to use the command pio boards (with examples)

The “pio boards” command is used to list pre-configured embedded boards available in PlatformIO.

Read More