find

Find architecture elements using query

Description

example

[paths] = find(object,constraint,Name,Value) finds all element paths starting from the root architecture of the model that satisfy the constraint query, with additional options specified by one or more name-value pair arguments.

example

[paths, elements] = find(___) returns the component elements and their paths that satisfy the constraint query. If rootArch is not provided, then the function finds model elements in the root architecture of the model. The output argument paths contains a fully qualified named path for each component in elements from the given root architecture.

example

[elements] = find(___) finds all component, port, or connector elements that satisfy the constraint query, with additional options specified by one or more name-value pair arguments, which must include 'Port' or 'Connector' for 'ElementType'.

example

[paths] = find(object,constraint,rootArch,Name,Value) finds all element paths starting from the specified root architecture that satisfy the constraint query, with additional options specified by one or more name-value pair arguments.

Examples

collapse all

Import a model and run a query to select architecture elements that have a stereotype based on the specified sub-constraint.

import systemcomposer.query.*;
scKeylessEntrySystem
modelObj = systemcomposer.openModel('KeylessEntryArchitecture');
find(modelObj,HasStereotype(IsStereotypeDerivedFrom('AutoProfile.BaseComponent')),...
 'Recurse',true,'IncludeReferenceModels',true)

Create a query to find components that contain the letter 'c' in their 'Name' property.

constraint = contains(systemcomposer.query.Property('Name'),'c');
find(modelObj,constraint,'Recurse',true,'IncludeReferenceModels',true)

This example shows how to find elements in an architecture model based on a query.

Create Model

Create an architecture model with two components.

m = systemcomposer.createModel('exModel');
comps = m.Architecture.addComponent({'c1','c2'});

Create Profile and Stereotypes

Create a profile and stereotypes for your architecture model.

pf = systemcomposer.profile.Profile.createProfile('mProfile');
b = pf.addStereotype('BaseComp', 'AppliesTo','Component','Abstract', true);
s = pf.addStereotype('sComp', 'Parent',b);

Apply Profile and Stereotypes

Apply the profile and stereotypes to your architecture model.

m.Architecture.applyProfile(pf.Name)
comps(1).applyStereotype(s.FullyQualifiedName)

Find the Element

Find the element in your architecture model based on a System Composer query.

import systemcomposer.query.*;
[p, elem] = find(m, HasStereotype(IsStereotypeDerivedFrom('mProfile.BaseComp')),...
'Recurse', true, 'IncludeReferenceModels', true)
p = 1x1 cell array
    {'exModel/c1'}

elem = 
  Component with properties:

     IsAdapterComponent: 0
           Architecture: [1x1 systemcomposer.arch.Architecture]
                   Name: 'c1'
                 Parent: [1x1 systemcomposer.arch.Architecture]
                  Ports: [0x0 systemcomposer.arch.ComponentPort]
             OwnedPorts: [0x0 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1x1 systemcomposer.arch.Architecture]
               Position: [15 15 65 65]
                  Model: [1x1 systemcomposer.arch.Model]
         SimulinkHandle: 2.0004
    SimulinkModelHandle: 3.6621e-04
                   UUID: '984b1ca4-e3d2-4b61-86d2-690f91a37f48'
            ExternalUID: ''

Clean Up

Uncomment to remove the model and the profile.

% m.close('force');
% systemcomposer.profile.Profile.closeAll;
  1. Create a model to query and create two components.

    m = systemcomposer.createModel('exModel');
    comps = m.Architecture.addComponent({'c1','c2'});
    port = comps(1).Architecture.addPort('cport1','in');
  2. Create a query to find ports that contain the letter 'c' in their 'Name' property, that returns only the elements.

    constraint = contains(systemcomposer.query.Property('Name'),'c');
    find(m,constraint,'Recurse',true,'IncludeReferenceModels',true,'ElementType','Port')
import systemcomposer.query.*;
scKeylessEntrySystem
modelObj = systemcomposer.openModel('KeylessEntryArchitecture');
find(modelObj,HasStereotype(IsStereotypeDerivedFrom('AutoProfile.BaseComponent')),...
 modelObj.Architecture,'Recurse',true,'IncludeReferenceModels',true)

Input Arguments

collapse all

Model, specified as a systemcomposer.arch.Model object to query using the constraint.

Query, specified as a systemcomposer.query.Constraint object representing specific conditions. A constraint can contain a sub-constraint that can be joined together with another constraint using AND or OR. A constraint can also be negated using NOT.

Query Objects and Conditions for Constraints

Query ObjectCondition
PropertyA non-evaluated value for the given property or stereotype property.
PropertyValueAn evaluated property value from a System Composer object or a stereotype property.
HasPortA component has a port that satisfies the given sub-constraint.
HasInterfaceA port has an interface that satisfies the given sub-constraint.
HasInterfaceElementAn interface has an interface element that satisfies the given sub-constraint.
HasStereotypeAn architecture element has a stereotype that satisfies the given sub-constraint.
IsInRangeA property value is within the given range.
AnyComponentAn element is a component and not a port or connector.
IsStereotypeDerivedFrom A stereotype is derived from the given stereotype.

Root architecture of the model, specified as a character vector.

Data Types: char

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: find(model,constraint,'Recurse',true,'IncludeReferenceModels',true)

Option to recursively search through model, or only search the specific layer, specified as the comma-separated pair consisting of 'Recurse' and a numeric or logical 1 (true) to recursively search or 0 (false) to only search the specific layer.

Example: find(model,constraint,'Recurse',true)

Data Types: logical

Option to search for reference architectures, or to not include referenced architectures, specified as the comma-separated pair consisting of 'IncludeReferenceModels' and a numeric or logical 0 (false) to not include referenced architectures or 1 (true) to search for referenced architectures.

Example: find(model,constraint,'IncludeReferenceModels',true)

Data Types: logical

Option to search by type, specified as the comma-separated pair consisting of 'ElementType' and 'Component' to select components to satisfy the query, 'Port' to select ports to satisfy the query, or 'Connector' to select connectors to satisfy the query.

Example: find(model,constraint,'ElementType','Port')

Data Types: char

Output Arguments

collapse all

Element paths, returned as a cell array of element paths that satisfy constraint.

Elements, returned as systemcomposer.arch.Element objects that satisfy constraint.

Introduced in R2019a