Main Content

addLifeline

Create new lifeline in interaction

Since R2024b

    Description

    lifeline = addLifeline(interaction,component) creates a lifeline in a sequence diagram corresponding to interaction, interaction, in a System Composer™ model using the component component.

    example

    Examples

    collapse all

    Create a sequence diagram programmatically to describe the scenario of a pedestrian crossing the street at an intersection with traffic lights.

    To learn more about sequence diagrams, see Author Sequence Diagrams Interactively.

    Open Traffic Light Example

    Load the TLExample architecture model.

    model = systemcomposer.openModel('TLExample');

    TLExample architecture model with various components.

    Create a new sequence diagram named 'InhibitCopy'.

    diagram = model.addInteraction('InhibitCopy');

    Add Lifelines

    Add a lifeline for each component in the architecture.

    sourceLifeline = diagram.addLifeline('TLExample/source');
    pollerLifeline = diagram.addLifeline('TLExample/poller');
    switchLifeline = diagram.addLifeline('TLExample/switch');
    lampLifeline = diagram.addLifeline('TLExample/lampController');
    controllerLifeline = diagram.addLifeline('TLExample/controller');

    Get the root fragment and root operand of the interaction.

    rootFragment = diagram.RootFragment;
    rootOperand = rootFragment.Operands(1);

    Add Messages and Fragments

    Add two messages to the root operand.

    sourceToPollerMsg = rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}");
    pollerToSwitchMsg = rootOperand.addMessage(pollerLifeline, "switchEvent", switchLifeline, "switchEvent", "switchEvent{switchEvent==1}");

    Add an alternative fragment to the root operand.

    altFrag = rootOperand.addFragment('Alt');

    Specify the guard expressions for each operand of the alternative fragment.

    op1 = altFrag.Operands(1);
    op1.Guard = "switch/inhibit==0";
    op2 = altFrag.addOperand("switch/inhibit==1");

    Add two messages to the first operand of the alternative fragment.

    switchToLampControllerMsg1 = op1.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==1}");
    switchToControllerMsg = op1.addMessage(switchLifeline, "switchPush", controllerLifeline, "pedRequest", "pedRequest");

    Add a message to the second operand of the alternative fragment.

    switchToLampControllerMsg2 = op2.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==2}");

    Add Duration Constraints

    Add a duration constraint between the two messages in the first operand of the alternative fragment.

    startEvent = switchToLampControllerMsg1.End;
    endEvent = switchToControllerMsg.End;
    expression = "t > 12msec";
    durationConstraint = diagram.addDurationConstraint(startEvent, endEvent, expression);

    Open Sequence Diagram

    Open the newly created sequence diagram.

    open(diagram);

    Newly created sequence diagram called 'InhibitCopy'.

    Input Arguments

    collapse all

    Interaction, specified as a systemcomposer.interaction.Interaction object.

    Component, specified as a systemcomposer.arch.Component object, a systemcomposer.arch.VariantComponent object, or the path to a component.

    Example: "KeylessEntryArchitecture/Lighting System/Headlights"

    Data Types: char | string

    Output Arguments

    collapse all

    Lifeline, returned as a systemcomposer.interaction.Lifeline object.

    More About

    collapse all

    Version History

    Introduced in R2024b