Main Content


(Not recommended) Generate XML data file for custom check for block constraints

Advisor.authoring.generateBlockConstraintsDataFile is not recommended. Use Advisor.authoring.createBlockConstraintCheck instead.

For more information, see Define Model Advisor Checks for Supported and Unsupported Blocks and Parameters.


Advisor.authoring.generateBlockConstraintsDataFile(dataFile, 'constraints',constraintslist) generates an XML data file named dataFile. This data file specifies the constraints that a custom check contains. The data file uses tagging to specify the constraint information. When you create a custom check, you use the data file.

Define constraint objects in the base workspace and then pass these objects as inputs to this function. These constraints may be root constraints and prerequisites to root constraints. You can also define a composite constraint. If you specify multiple root constraints and no composite constraint, Simulink implements a composite constraint with a CompositeOperator of and.


collapse all

Create a custom check for this MAB check Check settings for data ports in Multiport Switch blocks. For Multiport Switch blocks, the check contains a constraint that checks that the Data port order parameter setting is Specify indices. If the parameter has this setting, there are constraints that check that the Data port for default case parameter setting is Additional data port and the Diagnostic for default case setting is None.

Create three PositiveBlockParameter constraint objects.

c1 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c1.ID = 'ID_A2'; 
c1.BlockType = 'MultiPortSwitch'; 
c1.ParameterName = 'DataPortOrder'; 
c1.SupportedParameterValues = {'Specify indices'}; 
c1.ValueOperator = 'eq'; 

c2 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c2.ID = 'ID_A3'; 
c2.BlockType = 'MultiPortSwitch'; 
c2.ParameterName = 'DataPortForDefault'; 
c2.SupportedParameterValues = {'Additional data port'}; 
c2.ValueOperator = 'eq'; 

c3 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c3.ID = 'ID_A4'; 
c3.BlockType = 'MultiPortSwitch'; 
c3.ParameterName = 'DiagnosticForDefault'; 
c3.SupportedParameterValues = {'None'}; 
c3.ValueOperator = 'eq'; 

Use the addPreRequisiteConstraintID method to make c1 a prerequisite to checking constraints c2 and c3.


Create a composite constraint that specifies that if a Multiport Switch block does not meet constraints c2 and c3, the block is in violation of this check.

cc = Advisor.authoring.CompositeConstraint(); 
cc.addConstraintID ('ID_A4');
cc.CompositeOperator = 'and'; 

Create a data file that contains the constraints.

dataFile = 'myDataFile.xml';
Advisor.authoring.generateBlockConstraintsDataFile( ...

Data file myDataFile.xml has tagging specifying the constraint information for the custom check.

<?xml version="1.0" encoding="utf-8"?>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A2">
         <parameter type="string">DataPortOrder</parameter>
         <value>Specify indices</value>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A3">
         <parameter type="string">DataPortForDefault</parameter>
         <value>Additional data port</value>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A4">
         <parameter type="string">DiagnosticForDefault</parameter>


For model configuration parameter constraints, use the function Advisor.authoring.generateBlockConstraintsDataFile only when specifying model configuration parameter constraints as prerequisites to block constraints or as part of a composite constraint consisting of both block and model configuration parameter constraints. For other cases, use the function Advisor.authoring.generateConfigurationParameterDataFile.

Specify the data file myDataFile.xml as an input to the check definition function. To specify and register this check, use this sl_customization.m file.

function sl_customization(cm)
% SL_CUSTOMIZATION - Model Advisor customization demonstration.

% Copyright 2019 The MathWorks, Inc.

% register custom checks 


% -----------------------------
% defines Model Advisor Check
% -----------------------------
function defineBlockConstraintCheck

rec = Advisor.authoring.createBlockConstraintCheck('com.mathworks.sample.blockConstraint');
rec.Title = 'Example of block paramter constraints check';
    (system)), 'None', 'StyleOne');
rec.TitleTips = 'Example check for block paramter constraints';

% --- data file input parameters
rec.setInputParametersLayoutGrid([1 1]);
inputParam1 = ModelAdvisor.InputParameter;
inputParam1.Name = 'Data File';
inputParam1.Value = 'myDataFile.xml';
inputParam1.Type = 'String';
inputParam1.Description = 'Name or full path of XML data file.';
inputParam1.setRowSpan([1 1]);
inputParam1.setColSpan([1 1]);
rec.SupportExclusion = false;
rec.SupportLibrary = true;

% publish check into Demo group.
mdladvRoot = ModelAdvisor.Root;
mdladvRoot.publish(rec, 'Demo'); 


Input Arguments

collapse all

Name of XML data file to create, specified as a character vector.

Example: 'myDataFile.xml'

Use these classes to create constraint objects:

  • Advisor.authoring.PositiveBlockParameterConstraint

  • Advisor.authoring.NegativeBlockParameterConstraint

  • Advisor.authoring.PositiveModelParameterConstraint

  • Advisor.authoring.NegativeModelParameterConstraint

  • Advisor.authoring.PositiveBlockTypeConstraint

  • Advisor.authoring.NegativeBlockTypeConstraint

  • Advisor.authoring.CompositeConstraint

Example: {c1,c2,c3}

Version History

Introduced in R2018a

expand all