Main Content

makeVariantAssembly

Convert variant component to variant assembly component

Since R2023b

Description

variantAssemblyComp = makeVariantAssembly(variantComponent) converts the Variant Component block variantComponent to a Variant Assembly Component block and returns the Variant Assembly Component block object variantComponent. Use this syntax if the variant control mode of the Variant Component block is label and has only Model blocks and Create and Use Referenced Subsystems in Models blocks as its variant choices.

example

variantAssemblyComp = makeVariantAssembly(variantComponent,Name=Value) converts the Variant Component block variantComponent to a Variant Assembly Component block as specified by one or more Name-Value arguments and returns the Variant Assembly Component block object variantComponent. Use this syntax if the variant control mode of the Variant Component block is expression or has at least one Subsystem block as its variant choice.

example

Examples

collapse all

This example explains how to convert a Variant Component block in label mode to a Variant Assembly Component using the makeVariantAssembly function.

Create a model, get its root architecture, and create a variant component in label model.

model = systemcomposer.createModel("VariantComponentInLabelMode");
systemcomposer.openModel("VariantComponentInLabelMode");
arch = get(model,"Architecture");
variantComp = addVariantComponent(arch,'Controller');

Set the variant control mode of the Controller block to label.

vacBlockHandle = variantComp.SimulinkHandle;
set_param(vacBlockHandle,'VariantControlMode','label');

Convert the Variant Component to a Variant Assembly Component using the makeVariantAssembly function.

variantAssemblyComp = makeVariantAssembly(variantComp,SubsystemFilesFolderPath=pwd)
variantAssemblyComp = 
  VariantComponent with properties:

           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'Controller'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [0×0 systemcomposer.arch.ComponentPort]
             OwnedPorts: [0×0 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [280 349 380 422]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 219.0032
    SimulinkModelHandle: 153.0031
                   UUID: 'eb7cf36c-d000-45c6-bbb4-403bbf6bbb64'
            ExternalUID: ''

This example explains how to convert a Variant Component block in expression mode to a Variant Assembly Component using the makeVariantAssembly function.

Create a model, get its root architecture, and create a variant component in expression model.

model = systemcomposer.createModel("VariantComponentInExpressionMode");
systemcomposer.openModel("VariantComponentInExpressionMode");
arch = get(model,"Architecture");
variantComp = addVariantComponent(arch,'Controller');

Set the variant control mode of the Controller block to expression.

vacBlockHandle = variantComp.SimulinkHandle;
set_param(vacBlockHandle,'VariantControlMode','expression');

Convert the Variant Component to Variant Assembly Component using the makeVariantAssembly function. During the conversion process:

  • The current configuration of Variant Component is validated.

  • Any inline component choices are converted to Subsystem Reference choices.

  • An inline component with architecture type composition is converted to a Subsystem Reference component with composition. A new architecture subsystem file is created in this process.

  • An inline component with architecture type Simulink® behavior is converted to a Subsystem Reference component with Simulink behavior. A new Simulink subsystem file is created in this process.

SubsystemFilesFolderPath = pwd;
vcvName = 'EngType';
enumClassFilePath = 'controllerClass.m';
variantAssemblyComp = makeVariantAssembly(variantComp,SubsystemFilesFolderPath = pwd,VariantControlVariableName=vcvName,EnumerationClassFilePath=enumClassFilePath)
variantAssemblyComp = 
  VariantComponent with properties:

           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'Controller'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [0×0 systemcomposer.arch.ComponentPort]
             OwnedPorts: [0×0 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [280 349 380 422]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 219.0031
    SimulinkModelHandle: 153.0029
                   UUID: '5784df87-7467-406c-97e4-b4accb038863'
            ExternalUID: ''

Input Arguments

collapse all

Variant component, specified as a systemcomposer.arch.VariantComponent object.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: makeVariantAssembly(variantComp,SubsystemFilesFolderPath = pwd,VariantControlVariableName=vcvName,EnumerationClassFilePath=enumClassFilePath)

Valid MATLAB variable name or structure field name to be created, specified as a string scalar or a character vector. For the naming rules, see Variable Names and Generate Field Names from Variables.

During simulation, Simulink® uses the value of this parameter to determine the active variant choice of the converted Variant Assembly Component block.

Example: 'EngType'

Dependencies

Use this argument if the VariantControlMode parameter of the Variant Component block is set to 'expression'.

Data Types: char | string

Absolute or relative path to the MATLAB class file to be created, specified as a string scalar or a character vector. During the block conversion, Simulink defines an enumeration class in the specified enumeration class file with the variant choices of the converted Variant Assembly Component block as its members.

Example: 'ControllerType.m'

Dependencies

Use this argument if the VariantControlMode parameter of the Variant Component block is set to 'expression'.

Data Types: char | string

Absolute or relative folder path where the Subsystem Reference choices of the converted Variant Assembly Component block must be saved as subsystem files, specified as a string scalar or a character vector.

Example: SubsystemFilesFolderPath = 'ControllerChoices'

Dependencies

Use this argument if the Variant Component block has at least one Subsystem block as its variant choice.

Data Types: char | string

Output Arguments

collapse all

Variant assembly component, returned as a systemcomposer.arch.VariantComponent object.

Limitations

  • Only Variant Component blocks with the Variant control mode set to label or expression can be converted to a Variant Assembly Component block.

  • The conversion from Variant Component to Variant Assembly Component is not supported for software architecture and AUTOSAR architecture.

More About

collapse all

Alternatives

You can convert a Variant Component block to a Variant Assembly Component block through the block dialog. For more information, see Convert Variant Component to Variant Assembly Component.

Version History

Introduced in R2023b

expand all