Add Libraries to the Library Browser

This example shows how to create a block library and add it to the Simulink® Library Browser.

  1. In the Simulink Editor, select File > New > Library.

  2. Drag blocks from models or other libraries into the new library. You can modify the blocks in the library by changing block parameters, adding masks, or grouping blocks in subsystems.

  3. Save the library in a folder that is on the MATLAB® path. To add a folder to the MATLAB path, right-click the folder in MATLAB, and select Add to Path > Selected Folders and Subfolders.

  4. Open the library and unlock it by selecting Diagram > Unlock Library.

  5. At the MATLAB command prompt, enable the model property EnableLBRepository so that Simulink can add the library to the Library Browser.

  6. In MATLAB, open the folder containing the library. Right-click and select New File > Script.

  7. Save the file as slblocks.m.

  8. Open slblocks.m, and add this function into it.

    function blkStruct = slblocks
    		% This function specifies that the library should appear
    		% in the Library Browser
    		% and be cached in the browser repository
    		Browser.Library = 'mylib';
    		% 'mylib' is the name of the library
    		Browser.Name = 'My Library';
    		% 'My Library' is the library name that appears in the Library Browser
    		blkStruct.Browser = Browser;

    The figure shows the example library mylib.slx, which contains a Gain block, the Subsystem1 block, which uses default properties, and the Subsystem2 block. The OpenFcn property of the Subsystem2 block points to the library mylib2.

  9. Save the file slblocks.m. Open the Library Browser and refresh to view the new library. To refresh, right-click in the library list and select Refresh Library Browser.

    The figure shows the example library mylib with the library browser name My Library.

    Because of the callback you created, clicking Subystem2 shows the contents of the mylib2 library in the right pane.

You can specify the location of your library relative to the other libraries by adding your own sl_customization.m file to the MATLAB path and setting the sort priority of your library. For example, to see your library at the top of the list, you can set the sort priority to -2. By default, the sort priority of the Simulink library is -1. All the other libraries have a sort priority of 0.

This example shows sample content of the customization file that moves the new library to the top of the list of libraries.

function sl_customization(cm)
% Change the order of libraries in the Simulink Library Browser. 
cm.LibraryBrowserCustomizer.applyOrder({'My Library',-2});

For more information about registering user interface customizations, see Registering Customizations.

Was this topic helpful?