Conform to Software Architecture by Sharing and Copying Default Code Generation Settings Between Models

You and other users can configure default code generation settings for categories of model data and functions by using the Code Mappings editor (see Configure Default C Code Generation for Categories of Data Elements and Functions). You can also configure other model-wide code generation settings through configuration parameters. With these broad, general settings, you can make models generate code that conforms to a general software architecture by default.

As projects expand and you and other users create more models, manually configuring the default settings for each new model takes time. To reduce this manual data entry, you can write scripts and create templates that apply these default settings to new models.

You can copy settings between models, enabling each model to later change the settings independently of each other. Alternatively, you can share settings, enabling you to change the settings for multiple models at once with minimal effort.

Tools to Copy and Share Settings

ToolDescription and ConsiderationsReference
Template models

You can create a template model with preconfigured settings such as configuration parameter settings and Code Mappings editor settings.

However, when you create a model by instantiating a template, the new model is not linked to a data dictionary. If the preconfigured settings in the template model depend on shared data that you store in a data dictionary, you must configure dictionary linking and referencing for each new model.

Create a Template from a Model
Template projects

You can create a template project that contains models, data dictionaries, and other artifacts. You can also write project shortcuts that execute custom code to create models, copy settings, and share settings.

What Are Projects?
Programmatic interfaces

To copy settings between models, you can write scripts, callbacks, and shortcuts. Each kind of setting has a programmatic interface.

Techniques to Copy Settings
Configuration set objects

To share configuration parameter settings between models, you can create a configuration set object that each model can refer to.

Share a Configuration with Multiple Models
Data dictionaries

A Simulink® data dictionary stores variables, objects, and other data for one or more models. You can create hierarchies of referenced dictionaries to share configuration parameter settings and to partition and organize the settings.

It is a best practice to store shared settings in a standalone dictionary, which means that no models are linked to the dictionary. Then, you can link models to one or more additional, intermediate dictionaries, which you configure to refer to the standalone dictionary. With this modular dictionary hierarchy, each model can store other data, such as design data, separately from the shared settings.

For general information about data dictionaries, including how to access them programmatically, see What Is a Data Dictionary?. For an example that shows how to store shared data for a model reference hierarchy in a standalone dictionary, see Partition Data for Model Reference Hierarchy Using Data Dictionaries.

Techniques to Copy Settings

To copy settings, use one or more of the techniques described in the table.

TechniqueDescription
Create a template model.To create a model, you and other users can instantiate the template. Each new model can later change the settings independently of other models.
Create a template project.The template project can contain models and associated data dictionaries. Also, through custom project shortcuts and referenced projects, you can make shared data stored in a dictionary available to new models.
Write code by using programmatic interfaces.

You can execute this code in:

  • A script.

  • A model callback. For example, you can use the PreLoadFcn callback, which executes whenever you open a model. For information about model callbacks, see Model Callbacks.

To copy settings programmatically, use the programmatic interface.

Techniques to Share Settings

  • To share configuration parameter settings, create a configuration set object. Create a template model that refers to the object through a configuration reference.

    Consider storing the object in a data dictionary. Because you cannot create a template model that is linked to a data dictionary, you must configure dictionary linking and referencing for each new model.

  • You cannot share default data and function settings that you specify in the Code Mappings editor.

Related Topics