You can assign your messages sequential numbers automatically with the autonumber command.
Activation
Place the auto number command in your code, and the following messages will be numbered sequentially.
Example: Autonumber Activation
@startuml
'Example: Messages Autonumber
'Activate the autonumber method.
autonumber
'Send a few messages back and forth.
Sean -> Maria : Text
Sean <-- Maria : Text
Maria -> Zarek : Text
Maria <-- Zarek : Text
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Commands
stop - does what it says on the box, stops the sequential numbering
resume - resumes sequential numbering after using stop
inc - adds specific increments to specific sequences
Example: Stop & Resume
@startuml
'Example: Autonumber Stop & Resume
'Activate the autonumber method.
autonumber
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Stop the autonumber method.
autonumber stop
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Resume the autonumber method.
autonumber resume
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Properties
All autonumber properties are optional. Even if you don’t use all properties, they must be used in order. You must have a start_number if you wish to use increment. The format property contains three optional parts. There is no mandatory order inside of format.
start_number - the initial number used in the autonumber sequence, comes after the autonumber command
increment - the number added to the autonumber sequence with each message, comes after start_number or resume
format - determines the format of the sequential numbers consisting of three parts; the entire property must be inside of double quotes
number_format - provides a format for the sequential numbers
message - displays a message with the sequential numbers
text_format - similar to other formatting, usually surrounds the message and number_format
Start Number
The start_number property immediately follows the autonumber command. It defines the number that will begin the numbering sequence. Note that it can not be used after the resume command.
Example: Start Number
@startuml
'Example: Autonumber Start Number
'Activate the autonumber method.
'Start the sequence at 10.
autonumber 10
'Send a few messages.
Sean -> Maria : Text
Sean <-- Maria : Text
Maria -> Zarek : Text
Maria <-- Zarek : Text
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Increment
The increment property defines the step size between sequential numbers. It follows start_number or resume. When combined with resume, the new increment will begin on the second message after the resume command.
Example: Increment
@startuml
'Example: Autonumber Increment
'Activate the autonumber method.
'Start the sequence at 5 with an increment of 5.
autonumber 5 5
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Stop the autonumber method.
autonumber stop
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Resume the autonumber method with an increment of 2
autonumber resume 2
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Increment Option
If you want the sequential numbers in the above example to resume with an increment of two on the next message, you must manually restart autonumber. Use the autonumber command with start_number and increment again with the appropriate start_number.
Example: Increment Option
@startuml
'Example: Autonumber Increment Option
'Activate the autonumber method.
'Start the sequence at 5 with an increment of 5.
autonumber 5 5
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Stop the autonumber method.
autonumber stop
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Manually resume the autonumber method with an increment of 2
autonumber 12 2
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Number Format
The number_format property determines whether sequential numbers fill empty digits with zeroes. By using multiple zeroes, you are telling the number_format to keep zeroes as placeholders in unused digits.
Example: Number Format
@startuml
'Example: Autonumber Number Format
'Activate the autonumber method with a start_number of 7.
'Reserve three digits for the sequential number.
autonumber 7 "000"
'Send several messages.
Sean -> Maria : Text
Sean <-- Maria : Text
Maria -> Zarek : Text
Maria <-- Zarek : Text
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Message
The message property adds text to the sequential number. The number_format or # character determines where the sequential number will appear in relation to the message. Without an accompanying number_format or #, the message will appear to the left of the sequential number.
Example: Autonumber Message
@startuml
'Example: Autonumber Message
'Activate the autonumber method.
'Add a message.
autonumber "Message Here "
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Start a new autonumber method.
'Reserve two digits and place the sequential number before a message.
autonumber "00 Message Here"
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Start a new autonumber method.
'Do not reserve any digits and place the sequential number inside a message.
autonumber "Message # Here"
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Text Format
Example: Text Format
@startuml
'Example: Autonumber Text Format
'Activate the autonumber method.
'Make the sequential number underlined with creole.
autonumber "__#__"
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Start a new autonumber method.
'Add a message and make it purple with markup.
autonumber "<font color=561D5E>Message Here </font>"
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Start a new autonumber method.
'Add a message and reserve three digits.
'Make it all bold and cyan with markup.
autonumber "<font color=cyan><b>Message Here 000 </b></font>"
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
@enduml
Specific Sequence
You can build a sequence similar to version numbers using the autonumber method. By using any combination of four delimiters( . , : ; ). The specific sequence can be two or three digits. The specific sequence takes the place of the start_number. By default, the last digit will increment with each message. The inc command followed by the letters A or B allows you to manually increment the other digits. When A or B are incremented, all digits to the right will automatically reset to one. The specific sequence does not support any auto numberformat properties.
@startuml
'Example: Autonumber Specific Sequence
'Activate the autonumber method.
'Make a three digit specific sequence with two different delimiters.
autonumber 1;1:1
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
'Increase the second digit
autonumber inc B
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
'Start a new autonumber method.
''Make a three digit specific sequence with periods.
autonumber 1.1.1
'Send a message from Zarek to Sean and a reply.
Zarek -> Sean : Text
Zarek <-- Sean : Text
'Increase the first digit
autonumber inc A
'Send a message from Sean to Maria and a reply.
Sean -> Maria : Text
Sean <-- Maria : Text
@enduml
As a Variable
Example: As a Variable
@startuml
'Example: Autonumber As a Variable
'Activate the autonumber method.
autonumber
'Send a message from Sean to Maria and a reply.
'Put the sequence number in the message_text.
'Make the message text cyan.
Sean -> Maria : <color:#cyan>Text %autonumber%</color>
Sean <-- Maria : <color:#cyan>Text %autonumber%</color>
'Add a note with the autonumber value in the note.
note across : The current autonumber value is %autonumber%.
'Send a message from Maria to Zarek and a reply.
Maria -> Zarek : Text
Maria <-- Zarek : Text
@enduml
There are three commands that can follow autonumber. They are all optional. You will only need resume if you used stop, but it's not required. The inc command will be covered below in the section.
Stop & Resume
Start Number
Increment
Increment Option
Number Format Number Format
Autonumber Message
The text_format can affect the sequential number and the message. You can alter text_format with creole syntax for emphasis and markup language for color and emphasis. You can define colors with a standard color name or hex code. See for a list of creole and markup options.
Text Format Text Format
Specific Sequence
You can use the variable %autonumber% anywhere in your sequence diagram after starting the autonumber method. It will display the current value of the sequential number. For more on notes see the section.