Contenido principal

systemcomposer.activity.Action

Action node in activity diagram

Since R2026a

    Description

    An Action object represents an action node within an activity diagram model.

    Creation

    Create an action node in an activity diagram using the addNode function with the nodeType argument specified as action.

    action1 = addNode(activity,'MATLAB Action 1','action');  

    Properties

    expand all

    This property is read-only.

    To set this property, use the setBehaviorType function.

    Behavior type of action node, represented as one of these options:

    • MATLAB — Node contains an existing MATLAB® function such as rand, or a custom function written in an .m file

    • Activity — Node contains another activity diagram that consumes and produces tokens

    Child activity that defines behavior of the action node, specified as a systemcomposer.activity.Activity object.

    Dependencies

    This property is only available for action nodes with ActionBehavior set to Activity.

    Duration of the execution of action, specified as a double.

    Whether pin names are visible on the canvas, specified as 1 (true) or 0 (false).

    Data Types: logical

    Name of the MATLAB function file that defines the behavior, specified as a character vector.

    Dependencies

    This property is only available for action nodes with ActionBehavior set to MATLAB.

    Activity that contains the action node, specified as a systemcomposer.activity.Activity object.

    Pins defined for the activity, specified as an array of systemcomposer.activity.Pin objects.

    Name of action node, specified as a character vector.

    Example: 'action1'

    Data Types: char

    Position on canvas, specified as a vector of coordinates, in pixels: [left top right bottom].

    Each vector specifies the location of the top left corner and bottom right corner of the component, specified as a 1-by-4 numeric array. The array denotes the top left corner in terms of its x and y coordinates followed by the x and y coordinates of the bottom right corner.

    Data Types: double

    Parent activity diagram model, specified as a systemcomposer.activity.Model object.

    Simulink® handle, specified as a double.

    This property is necessary for several Simulink workflows and for using Requirements Toolbox™ programmatic interfaces.

    Example: handle = get(object,'SimulinkHandle')

    Data Types: double

    Universal unique identifier, specified as a character vector.

    Example: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'

    Data Types: char

    Unique external identifier, specified as a character vector. The external ID is preserved over the lifespan of the element and through all operations that preserve the UUID.

    Data Types: char

    Object Functions

    addPropertyDefine custom property for stereotype
    changeStereotypeChange currently applied stereotype to new stereotype in its stereotype hierarchy
    destroyRemove model element
    getEvaluatedPropertyValueGet evaluated value of property from element
    getFlowGet flow from activity diagram
    getPropertyGet property value corresponding to stereotype applied to element
    getPropertyValueGet value of architecture property
    getStereotypesGet stereotypes applied on model element
    hasPropertyFind if element has property
    removeStereotypeRemove stereotype from profile
    setPropertySet property value corresponding to stereotype applied to element
    addPinCreate new pin on action node
    applyStereotypeApply stereotype to model element
    connectCreate activity diagram flows
    getPinGet pin from action node
    getPinsGet pins from action node
    hasStereotypeFind if element has stereotype applied
    setBehaviorTypeSet behavior type of action node

    Examples

    collapse all

    This example shows how to create an activity diagram programmatically. An activity diagram describes system behavior that models the flow of tokens from inputs to outputs through a controlled sequence of actions. You can use activity diagrams to conceptualize a system, visualize functional flow through actions or decisions, and understand how system components interact with one another. To learn more about authoring activity diagram, see, Author a Simple Activity Diagram.

    In this example, you create an activity diagram to illustrate the steps involved in placing an order, checking inventory availability, and canceling the order if items are unavailable.

    Activity diagram for shopping process.

    Create New Activity Diagram

    Create a new activity diagram named AuthorActivity using the systemcomposer.createActivity function.

    activityName = 'AuthorActivity';
    adModel = systemcomposer.createActivity(activityName,true);
    activity = adModel.Activity;

    Add Initial Node and Action Nodes

    Add an initial node and required action nodes using the addNode function.

    init1 = addNode(activity,'init1','initial');
    action1 = addNode(activity,'Place Order','action');   
    action2 = addNode(activity,'Authorize Payment','action');  
    action3 = addNode(activity,'Check Inventory','action');  
    action4 = addNode(activity,'Cancel Order','action');  
    action5 = addNode(activity,'Fulfill Order','action'); 

    Define Action Node Behavior and Add Pins

    Add the behavior type of an action node using the setBehaviorType function. You can specify the MATLAB® functions for an action node with a behavior type of MATLAB by using the BehaviorDefinition property.

    setBehaviorType(action1,'MATLAB');
    action1.BehaviorDefinition = 'PlaceOrder';
    setBehaviorType(action2,'Activity');
    setBehaviorType(action3,'MATLAB');
    action3.BehaviorDefinition = 'CheckInventory';

    You can add pins on an action node using the addNode function. For more information on pins, see Pin.

    outPin1 = addPin(action1,'order','out');
    inPin1 = addPin(action2,'order1','in');
    outPin2 = addPin(action2,'order2','out');
    inPin2 = addPin(action3,'order3','in');
    outPin3 = addPin(action3,'order4','out');
    inPin1.IsStreaming = true;
    outPin2.IsStreaming = true;

    Create Nested Activity

    You can create a nested activity for an action node with Activity behavior type.

    childActivity = action2.ChildActivity;
    childAction1 = addNode(childActivity,'Enter Card Details','action');
    childAction2 = addNode(childActivity,'Authenticate Details','action');

    Add Control Nodes

    Add a join or fork node and a merge or decision node. For more information on control nodes, see systemcomposer.activity.ControlNode.

    jfork = addNode(activity,"jfork","joinfork"); 
    decMerge1 = addNode(activity,"decMerge1","mergedecision");
    decMerge2 = addNode(activity,"decMerge2","mergedecision");

    Add Flow Final and Activity Final Nodes

    Add a flow final node and an activity final node.

    ffinal = addNode(activity,"ffinal","flowfinal");
    afinal = addNode(activity,"afinal","activityfinal");

    Connect Flows

    Connect the flows to complete the activity diagram. You can create guard expressions for flows that output from decision node.

    flow1 = connect(init1,action1);
    flow2 = connect(outPin1,jfork);
    flow3 = connect(jfork,inPin1);
    flow4 = connect(jfork,inPin2);
    flow5 = connect(outPin2,decMerge1);
    flow6 = connect(outPin3,decMerge2);
    flow7 = connect(decMerge2,action5);
    flow8 = connect(decMerge2,action4);
    flow9 = connect(decMerge1,action5);
    flow10 = connect(decMerge1,action4);
    flow11 = connect(action4,ffinal);
    flow12 = connect(action5,afinal);

    Create guard expression for flows that output from decision node.

    flow7.Guard = 'token == 1';
    flow8.Guard = 'token == 0';

    You can use the Simulink.BlockDiagram.arrangeSystem function to improve the layout of the activity diagram model.

    Simulink.BlockDiagram.arrangeSystem('AuthorActivity');

    More About

    expand all

    Version History

    Introduced in R2026a