Link Data Dictionary to Custom Libraries - MATLAB & Simulink (original) (raw)

Main Content

When you create a custom block library, you might define data objects — such as bus and enumeration types — to be used on block interfaces. You can make these data types available to library users by storing them in a Simulink® data dictionary that is linked to the library. Library users automatically gain access to the data types contained in the dictionary when they drag a block from the library into their model.

Author Library Blocks with Data Types Defined in Linked Data Dictionary

To define data and types for your library blocks in a data dictionary:

  1. Create a new data dictionary or open an existing dictionary. To create a new dictionary, in the Model Explorer, select > > . To open an existing dictionary, select > and browse for your dictionary.
  2. Add data and types, such as bus objects, to the data dictionary.
    View of Model Explorer. On the left, a data dictionary node is expanded in the Model Hierarchy pane. On the right, the Contents pane displays the two bus objects contained in the Design Data section of the dictionary.
  3. Save the data dictionary.

You can link the data dictionary to your library by using the UI or programmatically by using the set_param function.

To link the data dictionary by using the UI:

  1. Unlock your library using any of these options:
    • In the Library window, click the lock badge in the lower-left corner.
    • In the Library tab of the Simulink Toolstrip, in the Protect section, clickLocked Library.
    • In the MATLAB Command window, use theset_param function to set theLock parameter of the library:
      set_param("myLibrary","Lock","off")
  2. In the Simulink Editor, on the Modeling tab, clickLibrary Properties.
  3. In the Library Properties dialog box, on the External Data tab, click Browse to locate and open your data dictionary.
  4. Click OK to link the dictionary.

To link the data dictionary by using the set_param function, use this command.

set_param('myLib','DataDictionary','myLibData.sldd');

After you have linked the dictionary and saved your library, the dictionary and its content appears in the Model Explorer as an external data source for the library.

View of Model Explorer. On the left, the library node is expanded in the Model Hierarchy pane. Under the library node, the External Data node is expanded to show the linked data dictionary. On the right, the Contents pane displays the two bus objects contained in the Design Data section of the dictionary.

As you develop blocks for your library, you can select the types contained in the library dictionary from the Data type list.

On the left, the model canvas displays the contents of a subsystem library block. The Out block is selected. On the right, a block parameters dialog box displays the dictionary data types in the drop-down menu for Data type.

Use Blocks From a Library with Linked Data Dictionary

When you drag a block from a library into your model, the model automatically gains access to data objects contained in the dictionary linked to that library. To see the dictionary in the Model Explorer, in the Simulink Editor, click the model data badge in the bottom left corner, then click External Data. The dictionary appears as an external data source to your model under the From Libraries node.

View of Model Explorer. On the left, a model node is expanded in the Model Hierarchy pane. Under the model node, the External Data node is expanded. Under the External Data node, the From Libraries node is expanded to show the linked data dictionary. On the right, the Contents pane displays the two bus objects contained in the Design Data section of the dictionary.

The data objects defined in the library are now available to the model for simulation and code generation without the need to bring those data objects into either the base workspace or another data dictionary.

On the left, the model canvas displays a library block used in a model. The Out block is selected. On the right, a block parameters dialog box displays the dictionary data types in the drop-down menu for Data type.

When you update or save your model, if the model no longer contains a block from the library, the library dictionary is no longer available to your model and the dictionary is removed from the From Libraries node.

Considerations When Using a Library Dictionary

There are several considerations when authoring or using a library with a linked data dictionary.

See Also

set_param | Simulink.LibraryDictionary.refresh | Simulink.LibraryDictionary.clear | Simulink.LibraryDictionary.resetLibraryLinks

Topics