Main Content

Create Architecture Views Programmatically

You can create an architecture view programmatically. This topic presents two examples of creating architecture views programmatically using a keyless entry system architecture using element groups.

For an overview of topics on views, see Create Custom Views Using Architecture Views Gallery.

An element group is a grouping of components in a view.

Use element groups to programmatically populate a view.

For more information on the keyless entry architecture, see Modeling System Architecture of Keyless Entry System.

The third example is about how to use queries to find elements in a System Composer™ model.

A query is a specification that describes certain constraints or criteria to be satisfied by model elements.

Use queries to search elements with constraint criteria and to filter views.

Tip

To learn more about how System Composer concepts apply to systems engineering design, see System Composer Concepts.

Create Architecture Views in System Composer with Keyless Entry System

Use a keyless entry system architecture model to programmatically create views.

Import the namespace with queries.

import systemcomposer.query.*

Open the Simulink® project file for the keyless entry system.

openProject("scKeylessEntrySystem");

Load the example model into System Composer™.

model = systemcomposer.loadModel("KeylessEntryArchitecture");

Hardware Component Review Status View

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

1. Construct a query to select all hardware components.

hwCompQuery = HasStereotype(IsStereotypeDerivedFrom("AutoProfile.HardwareComponent"));

2. Use the query to create a view.

model.createView("Hardware Component Review Status",...
 Select=hwCompQuery,...
 GroupBy={'AutoProfile.BaseComponent.ReviewStatus'},...
 IncludeReferenceModels=true,...
 Color="purple");

3. To open the Architecture Views Gallery the Modeling section, click Architecture Views.

model.openViews

Hardware component review status component diagram view.

FOB Locater System Supplier View

Create a view with components from the FOB Locater System and group them using existing and new view components for the suppliers. In this example, you will use element groups, groupings of components in a view, to programmatically populate a view.

1. Create a view architecture.

fobSupplierView = model.createView("FOB Locater System Supplier Breakdown",...
    Color="lightblue");

2. Add a subgroup called Supplier D. Add the FOB Locater Module to the view element subgroup.

supplierD = fobSupplierView.Root.createSubGroup("Supplier D");
supplierD.addElement("KeylessEntryArchitecture/FOB Locater System/FOB Locater Module");

3. Create a new subgroup for Supplier A.

supplierA = fobSupplierView.Root.createSubGroup("Supplier A");

4. Add each of the FOB Receivers to the view element subgroup.

FOBLocaterSystem = model.lookup("Path","KeylessEntryArchitecture/FOB Locater System");

Find all the components which contain the name Receiver.

receiverCompPaths = model.find(...
    contains(Property("Name"),"Receiver"),...
    FOBLocaterSystem.Architecture);

supplierA.addElement(receiverCompPaths)

FOB locater system supplier view component diagram.

Find Elements in Model Using Queries

Find components in a System Composer model using queries.

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

import systemcomposer.query.*

Open the model.

openProject("scKeylessEntrySystem");
model = systemcomposer.loadModel("KeylessEntryArchitecture");

Find all the software components in the system.

con1 = HasStereotype(Property("Name") == "SoftwareComponent");
[compPaths,compObjs] = model.find(con1)
compPaths = 5x1 cell
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                 }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'         }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'           }

compObjs=1×5 Component array with properties:
    IsAdapterComponent
    Architecture
    ReferenceName
    Name
    Parent
    Ports
    OwnedPorts
    OwnedArchitecture
    Parameters
    Position
    Model
    SimulinkHandle
    SimulinkModelHandle
    UUID
    ExternalUID

Include reference models in the search.

softwareComps = model.find(con1,IncludeReferenceModels=true)
softwareComps = 9x1 cell
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                                                 }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller'                                 }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Sensor/Detect Door Lock Status' }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Sensor/Detect Door Lock Status'   }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'                                         }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'                                }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Sensor/Detect Door Lock Status'}
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Sensor/Detect Door Lock Status'  }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'                                           }

Find all the base components in the system.

con2 = HasStereotype(IsStereotypeDerivedFrom("AutoProfile.BaseComponent"));
baseComps = model.find(con2)
baseComps = 18x1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Actuator'  }
    {'KeylessEntryArchitecture/FOB Locater System/Center Receiver'                      }
    {'KeylessEntryArchitecture/Engine Control System/Start//Stop Button'                }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Sensor'    }
    {'KeylessEntryArchitecture/FOB Locater System/Rear Receiver'                        }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Actuator' }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Sensor'   }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Sensor'  }
    {'KeylessEntryArchitecture/Sound System/Dashboard Speaker'                          }
    {'KeylessEntryArchitecture/FOB Locater System/Front Receiver'                       }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Actuator'}
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                           }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller'           }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Actuator'   }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'                   }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'          }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Sensor'     }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'                     }

Find all components using the interface KeyFOBPosition.

con3 = HasPort(HasInterface(Property("Name") == "KeyFOBPosition"));
con3_a = HasPort(Property("InterfaceName") == "KeyFOBPosition");
keyFOBPosComps = model.find(con3)
keyFOBPosComps = 10x1 cell
    {'KeylessEntryArchitecture/Sound System'                                  }
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                 }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/FOB Locater System'                            }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'         }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'           }
    {'KeylessEntryArchitecture/Lighting System'                               }
    {'KeylessEntryArchitecture/Door Lock//Unlock System'                      }
    {'KeylessEntryArchitecture/Engine Control System'                         }

Find all components whose WCET is less than or equal to 5 ms.

con4 = PropertyValue("AutoProfile.SoftwareComponent.WCET") <= 5;
model.find(con4)
ans = 1x1 cell array
    {'KeylessEntryArchitecture/Sound System/Sound Controller'}

You can specify units for automatic unit conversion.

con5 = PropertyValue("AutoProfile.SoftwareComponent.WCET") <= Value(5,'ms');
query1Comps = model.find(con5)
query1Comps = 3x1 cell
    {'KeylessEntryArchitecture/Sound System/Sound Controller'        }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'  }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'}

Find all components whose WCET is greater than 1 ms or that have a cost greater than 10 USD.

con6 = PropertyValue("AutoProfile.SoftwareComponent.WCET") > Value(1,'ms') | PropertyValue("AutoProfile.Base.Cost") > Value(10,'USD');
query2Comps = model.find(con6)
query2Comps = 2x1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}

See Also

Tools

Functions

Objects

Related Topics