Search code examples
plantuml

How do I auto activate and destroy in a plant uml sequence diagram


In PlantUML adding activation lines in a sequence diagram can be very messy. Is there any way to make it auto activate and deactivate without all the extra text?

e.g.

Generate Sequence diagram without activation lines

@startuml

First -> Second
Second -> Third
Third -> Second
Second ->  First

@enduml

enter image description here

But to add the activation lines its gets quite messy

@startuml

First -> Second : message
activate First
activate Second
Second -> Third: message
activate Third
Third -> Second: response
deactivate Third
Second ->  First: response
deactivate First
deactivate Second

@enduml

enter image description here

I'm wondering if there is its possible to have it auto detect the likely create destroy points automatically


Solution

  • Yes (2017) with autoactivate on; the syntax is still in incubation, however it has been part of the distribution for some time.

    Note that in all cases you still need to manually activate the First one, because there's no incoming message.

    Compact syntax

    If you want to maintain control of the (de)activation, you can express activation/deactivation with ++ and -- symbols on the same line to activate the target.

    activate First
    First -> Second ++ : message12
    Second -> Third ++ : message23
    Third -> Second -- : response32
    Second ->  First -- : response21
    deactivate First
    

    enter image description here

    autoactivate on

    With your original description you will quickly find out that you need to describe your lines properly as a return, otherwise you'll be activating ad nauseam.

    autoactivate on
    activate First
    First -> Second
    Second -> Third
    Third --> Second
    Second --> First
    deactivate First
    

    enter image description here