Main Content

findElementsOfType

Find all elements of specific type

Since R2023a

    Description

    elements = findElementsOfType(containerObj,kind) finds all elements elements of the type kind.

    example

    elements = findElementsOfType(containerObj,kind,Name=Value) finds all elements of a type with additional options specified by one or more name-value arguments.

    Examples

    collapse all

    Use functions in the System Composer™ query namespace to filter elements in a model.

    Import the namespace that contains all of the System Composer queries.

    import systemcomposer.query.*

    Load the model and the profile.

    sysModel = systemcomposer.loadModel("mBasicModel");
    basicProfile = systemcomposer.loadProfile("mProfile");

    Find all components in the model.

    allComps = findElementsOfType(sysModel,"Component")
    allComps=1×10 Component array with properties:
        IsAdapterComponent
        Architecture
        ReferenceName
        Name
        Parent
        Ports
        OwnedPorts
        OwnedArchitecture
        Parameters
        Position
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    Find all ports in the model.

    allPorts = findElementsOfType(sysModel,"Port")
    allPorts=1×19 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    Find all stereotypes in the model.

    allStereotypes = findElementsOfType(basicProfile,"Stereotype")
    allStereotypes=1×10 Stereotype array with properties:
        Name
        Description
        Parent
        AppliesTo
        Abstract
        Icon
        ComponentHeaderColor
        ConnectorLineColor
        ConnectorLineStyle
        FullyQualifiedName
        Profile
        OwnedProperties
        Properties
    
    

    Find all interfaces in the model.

    allInterfaces = findElementsOfType(sysModel,"Interface")
    allInterfaces=1×7 heterogeneous Interface (ValueType, PhysicalInterface, DataInterface) array with properties:
        UUID
        ExternalUID
    
    

    Find components in the model with a name containing "c1".

    nameComponents = findElementsWithProperty(sysModel,"Component","Name","c1","contains")
    nameComponents=1×2 Component array with properties:
        IsAdapterComponent
        Architecture
        ReferenceName
        Name
        Parent
        Ports
        OwnedPorts
        OwnedArchitecture
        Parameters
        Position
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    Find all stereotypes in the profile with a name containing "BasePort".

    basePortStereotype = findElementsWithProperty(basicProfile,"Stereotype","Name","BasePort","eq")
    basePortStereotype = 
      Stereotype with properties:
    
                        Name: 'BasePort'
                 Description: ''
                      Parent: [0×0 systemcomposer.profile.Stereotype]
                   AppliesTo: 'Port'
                    Abstract: 1
                        Icon: ''
        ComponentHeaderColor: [210 210 210]
          ConnectorLineColor: [168 168 168]
          ConnectorLineStyle: 'Default'
          FullyQualifiedName: 'mProfile.BasePort'
                     Profile: [1×1 systemcomposer.profile.Profile]
             OwnedProperties: [0×0 systemcomposer.profile.Property]
                  Properties: [0×0 systemcomposer.profile.Property]
    
    

    Find all components in the model using the stereotype "BasePort".

    basePorts = findElementsWithStereotype(sysModel,"Port",basePortStereotype)
    basePorts=1×18 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    Find all elements using the first two found interfaces.

    portsUsingInterfaces = findElementsWithInterface(sysModel,"Port",[allInterfaces(1) allInterfaces(2)])
    portsUsingInterfaces=1×2 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    Input Arguments

    collapse all

    Element type, specified as one of these options:

    • "Component"

    • "Port"

    • "Connector"

    • "Interface"

    • "InterfaceElement"

    • "Stereotype"

    Data Types: string

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: allComps = systemcomposer.query.findElementsOfType(sysModel,"Component",NegateResult=true,IncludeReferences=false)

    Whether to negate query result, specified as 1 (true) or 0 (false).

    Data Types: logical

    Option to search through reference architectures, specified as 1 (true) or 0 (false).

    Data Types: logical

    Output Arguments

    collapse all

    More About

    collapse all

    Version History

    Introduced in R2023a