Reuse of sequence diagram parts
Asked Answered
L

6

8

I have multiple single sequence diagrams. most of them have the same initialization and termination sequence.

It is possible to copy this from one file to the other but it would be much better if this part could be declared at a single point. So in case of a change it would not be necessary to change all the diagrams.

Is there a way to do this ?

Laurence answered 13/4, 2017 at 9:45 Comment(0)
L
3

I tried to comment to JRI's answer but I don't have a high enough reputation.

I found that !include works until you need to include the same file multiple times. I got a solution on a plantuml forum and I can't remember the forum but I do remember the solution. On the second and each additional time you include a file you want to use !include_many.

Loyalty answered 24/1, 2018 at 19:42 Comment(0)
I
4

@user349062 comment is the correct answer. This was not easy to find, and its not in the documentation: Reference Guide

Using !include_many instead of !include in subsequent pages works, which doesn't make much sense, but there you go.

Interconnect answered 2/11, 2018 at 12:2 Comment(0)
L
3

I tried to comment to JRI's answer but I don't have a high enough reputation.

I found that !include works until you need to include the same file multiple times. I got a solution on a plantuml forum and I can't remember the forum but I do remember the solution. On the second and each additional time you include a file you want to use !include_many.

Loyalty answered 24/1, 2018 at 19:42 Comment(0)
L
2

Yes, you should use a reference fragment to reference the separate initialization / termination sequences:

@startuml
participant Alice
participant Bob
ref over Alice, Bob : initialization
Alice -> Bob : hello
ref over Alice, Bob : termination
@enduml
Lactase answered 14/4, 2017 at 23:4 Comment(1)
How to use ref over in activity-diagram ?Babel
D
2

If you want to show the detail of the re-used parts, rather than abstract them away as a reference block, PlantUML allows you to include files using the !include or !includeurl directives.

The syntax also allows you to import particular blocks of code from an imported file. See http://plantuml.com/preprocessing for details.

Dermot answered 23/6, 2017 at 17:19 Comment(0)
S
1

You could use !include directives to incorporate the common aspect of your sequence diagrams into your files.

By default, a file can only be included once. You can use !include_many instead of !include if you want to include some file several times. Note that there is also a !include_once directive that raises an error if a file is included several times.

-- https://plantuml.com/preprocessing#393335a6fd28a804

Stibine answered 27/10, 2023 at 3:4 Comment(0)
P
0

To add to the existing answers there is also the !includesub directive to be used in conjunction with the !startsub/!endsub directives. See the https://plantuml.com/preprocessing instructions

  • partial.puml
@startuml partial

!startsub PARTIAL

  A -> B
  activate B
  A <-- B
  deactivate B

!endsub

@enduml

  • main.puml
@startuml main

!includesub partial.puml!PARTIAL

@enduml
Postdiluvian answered 4/9, 2024 at 19:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.