Main Content

coder.dictionary.copy

Copy code generation definitions between models and data dictionaries

Description

example

copy(sourceName,destinationName) copies code generation definitions, such as storage classes, from the Embedded Coder Dictionary in sourceName to the Embedded Coder Dictionary in destinationName.

If a code generation definition in sourceName has the same name as a definition in destinationName, copy copies the source entry into the destination, and then renames the copy.

To share code definitions between models, use a Simulink® data dictionary, as described in Share Embedded Coder Dictionary Definition Between Models. To copy individual code definitions, use the Embedded Coder Dictionary dialog box or copyEntry. For general information about Embedded Coder Dictionaries and code generation definitions, see Define Storage Classes, Memory Sections, and Function Templates for Software Architecture.

Examples

collapse all

In the Embedded Coder Dictionary of the example model rtwdemo_roll, create a storage class. Then, copy the storage class to the Embedded Coder Dictionary in rtwdemo_rtwecintro.

Open the model rtwdemo_roll and represent the Embedded Coder Dictionary by using a coder.Dictionary object. Use this object to access the Storage Classes section of the dictionary and represent the section by using a coder.dictionary.Section object.

rtwdemo_roll
coderDictionary = coder.dictionary.open('rtwdemo_roll');
storageClassesSect = getSection(coderDictionary, 'StorageClasses');

Add a storage class definition named MyStorageClass to the Storage Classes section. The storage class definition uses the default property settings.

newEntry = addEntry(storageClassesSect,'MyStorageClass')
newEntry = 

  Entry with properties:

          Name: 'MyStorageClass'
    DataSource: 'rtwdemo_roll'

Save a copy of rtwdemo_roll in your current folder. Saving the model saves the storage class in the Embedded Coder Dictionary.

Open the other model, rtwdemo_rtwecintro.

rtwdemo_rtwecintro

Copy the contents of the Embedded Coder Dictionary in rtwdemo_roll to the Embedded Coder Dictionary in rtwdemo_rtwecintro.

coder.dictionary.copy('rtwdemo_roll','rtwdemo_rtwecintro')

Open the Embedded Coder Dictionary for rtwdemo_rtwecintro.

In the Embedded Coder Dictionary window, on the Storage Classes tab, the storage class MyStorageClass appears.

Input Arguments

collapse all

Source model file or data dictionary, specified as a character vector or string scalar.

  • A model must be loaded (for example, by using load_system) or open.

    You do not need to specify the .slx file extension.

  • A dictionary must be open in the Model Explorer, in the current folder, or on the MATLAB® path.

    You must specify the .sldd file extension.

Example: 'myLoadedModel'

Example: 'myDictionary.sldd'

Data Types: char

Destination model file or data dictionary, specified as a character vector or string scalar.

  • A model must be loaded (for example, by using load_system) or open.

    You do not need to specify the .slx file extension.

  • A dictionary must be open in the Model Explorer, in the current folder, or on the MATLAB path.

    You must specify the .sldd file extension.

Example: 'myLoadedModel'

Example: 'myDictionary.sldd'

Data Types: char

Introduced in R2018a