Find architecture elements using a query



[p] = find(obj,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.


[p, elem] = find(___) returns the architecture element objects 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 contain a fully qualified named path to the element e from the given root architecture.


[p] = find(obj,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.


collapse all

find(modelObj, HasStereotype(IsStereotypeDerivedFrom('mProfile.BaseComp')),...
 'Recurse', true, 'IncludeReferenceModels', true, 'ElemType', 'Component')

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.


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

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.0005
    SimulinkModelHandle: 4.8828e-04
                   UUID: '7c02c1d5-da2c-4115-968d-1b7cb6a4845a'
            ExternalUID: ''

Clean Up

Uncomment to remove the model and the profile.

% m.close('force');
% systemcomposer.profile.Profile.closeAll;
find(modelObj, HasStereotype(IsStereotypeDerivedFrom('mProfile.BaseComp')),... 
archToQuery, 'Recurse', true, 'IncludeReferenceModels', true)

Input Arguments

collapse all

Model object to query using the constraint.

Constraint created using systemcomposer.query* objects representing specific conditions. A constraint can contain a subconstraint that can be joined together with another constraint using AND or OR. A constraint can also be negated using NOT.

Query Objects

Query ObjectCondition
PropertyRetrieve a nonevaluated value or the given property.
PropertyValueRetrieve a property from a System Composer object or a stereotype property and then evaluate the property value.
CompareCompare a property value to the given value.
HasPortA component has a port that satisfies the given subconstraint.
HasInterfaceA port has an interface that satisfies the given subconstraint.
HasInterfaceElementAn interface has an interface element that satisfies the given subconstraint.
HasStereotypeAn architecture element has a stereotype that satisfies the given subconstraint.
IsInRangeA property value is within the given range.
AnyComponentsAn element is a component.
IsStereotypeDerivedFrom A stereotype is derived from the given stereotype.

Root architecture of the model specified as a string.

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: 'Recurse', true, 'IncludeReferenceModels', true

Indicates if find recursively searches through the model or searches only the specified layer. The default is true.

Example: 'Recurse', true

Indicates if find searches referenced architectures or does not include referenced architectures. The default is false.

Example: 'IncludeReferenceModels', true

Output Arguments

collapse all

Cell array of paths to the elements that satisfy constraint.

Architecture element objects that satisfy constraint.

Introduced in R2019a