Skip to main content

Get messages

Get all messages from a sequence diagram

To get all messages, use the Messages property of the ISequenceDiagram object.

public void GetMessages(ICommandContext c, ICommandParams p) 
{
ISequenceDiagram sequenceDiagram = c.App.Workspace.CurrentEditor as ISequenceDiagram;
if (sequenceDiagram == null) return;

//Get messages
IMessageShapeCollection messages = sequenceDiagram.Messages;

var no = 1;
foreach (IMessageShape message in messages)
{
c.App.Output.WriteLine("sample", $"{no}th message : {message.Text}");
no++;
}
}

Get sent messages from a specific lifeline

An example of getting sent messages from a specific lifeline.

public void GetSendMessages(ICommandContext c, ICommandParams p) 
{
ISequenceDiagram sequenceDiagram = c.App.Workspace.CurrentEditor as ISequenceDiagram;
if (sequenceDiagram == null) return;

//Get the send messages from the execution specifications of the selected lifeline
ILifelineShape lifeline = sequenceDiagram.GetSelectedShapes().FirstOrDefault() as ILifelineShape;
IMessageShapeCollection sendMessages = lifeline.ExecutionSpecifications.SelectMany(ec => ec.SendMessages);

c.App.Output.WriteLine("sample", $"Lifeline: Send Messages for {lifeline.Text}");

var no = 1;
foreach (IMessageShape sendMessage in sendMessages)
{
c.App.Output.WriteLine("sample", $" {no}th sent message: {sendMessage.Text}");
no++;
}
}