Main Content

Creating Architectural Views Programmatically

You can create an architecture view programmatically. This section constrains two examples for creating views programmatically from the MATLAB script createArchitectureViews.m.

  1. Import the package where the queries are so you don't have to always use systemcomposer.query.

    import systemcomposer.query.*;
  2. Open the Simulink project file.

  3. Load the example model into Simulink.

    zcModel = systemcomposer.loadModel('KeylessEntryArchitecture');

Example 1: Hardware Component Review Status

Create a filtered view that selects all of the hardware components in the architecture model and groups them using the ReviewStatus property.

  1. Construct the query to select all of the hardware components.

    hwCompQuery = HasStereotype(IsStereotypeDerivedFrom("AutoProfile.HardwareComponent"))
    hwCompQuery = 
      HasStereotype with properties:
        AllowedParentConstraints: {[1×1 meta.class]}
                   SubConstraint: [1×1 systemcomposer.query.IsStereotypeDerivedFrom]
                  SkipValidation: 0
  2. Use the query to create a view.

    zcModel.createViewArchitecture("Hardware Component Review Status",...
        hwCompQuery,... % The query to use for the selection
        "AutoProfile.BaseComponent.ReviewStatus",... % The stereotype property to qualify by
        "IncludeReferenceModels",true,... % Include components in referenced models

    View browser display after the open views command.

Example 2: FOB Locator System Supplier View

This example shows hot to create a freeform view that manually pulls the components from the FOB Locator system and then groups them using existing and new view components for the suppliers.

  1. Create a view architecture.

    fobSupplierView = zcModel.createViewArchitecture("FOB Locator System Supplier Breakdown",...
  2. Create a new view component for supplier D and add the FOB Locator module to it.

    supplierD = fobSupplierView.createViewComponent("Supplier D");
    supplierD.Architecture.addComponent("KeylessEntryArchitecture/FOB Locator System/FOB Locator Module");
  3. Create a new view component for supplier A.

    supplierA = fobSupplierView.createViewComponent("Supplier A");
  4. Add each of the FOB receivers to view component.

    FOBLocatorSystem = zcModel.lookup("Path", "KeylessEntryArchitecture/FOB Locator System");
    receiverCompPaths = zcModel.find(...
        contains(systemcomposer.query.Property("Name"),"Receiver"),... % Find all the components which contain the name "Receiver"
    for i = 1:numel(receiverCompPaths)
        % Add each of the components to supplier A
  5. Open the Views Editor.


    View browser display after the open views command.

  6. Close the model.


Finding Elements in a System Composer Model Using Queries

This example shows how to find components in a system composer model using queries.

  1. Open the MATLAB script.

  2. Review the 6 example queries.