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.

    scKeylessEntrySystem
  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
        "Color", "purple");
    
    zcModel.openViews;

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", ...
        "Color", "lightblue");
  2. Create a new view component for supplier D and add the FOB Locator module to it.

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

    supplierA = fobSupplierView.createViewComponent("Supplier A", fobSupplierView);
  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"
        FOBLocatorSystem.Architecture);
    
    for i = 1:numel(receiverCompPaths)
        % Add each of the components to supplier A
        supplierA.Architecture.addComponent(receiverCompPaths{i}, fobSupplierView);
    end
  5. Open the Views Editor.

    zcModel.openViews;

  6. Close the model.

    zcModel.close('Force');

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.

    open('scExampleModelFind')
  2. Review the 6 example queries.