To use imported blocks from your library, open the Simulink
model, then copy the blocks into a new Model Composer model. You can also see your library
listed in the Library Browser, and drag and drop blocks from the library into new models. To
do this, after running the xmcImportFunction command you must
prepare your library as follows:
- Enable the Library Browser parameter.
- Save the library.
- Create slblocks.m script for the library.
- Add path to MATLAB, or add library to MATLAB path.
- Refresh Library Browser.
To enable the library to be available in the Library Browser, you must turn
on the EnableLBRepository parameter for the library. After
importing a block into a new library using xmcImportFunction,
with the library open, you must use the following command from the MATLAB
command line prior to saving your library:
set_param(gcs,'EnableLBRepository','on');
This parameter identifies the library as belonging to the Library Browser.
However, that is only the first step. Save the library by clicking from the main menu, or by clicking the button in the toolbar.
function blkStruct = slblocks
% This function adds the library to the Library Browser
% and caches it in the browser repository
% Specify the name of the library
Browser.Library = 'newlib';
% Specify a name to display in the library Browser
Browser.Name = 'New Library';
blkStruct.Browser = Browser;
Browser.Library specifies the
name of the library model minus the .slx file extension.
Browser.Name specifies the display name that appears in
Library Browser.path at the MATLAB command prompt to see the current path that MATLAB uses. You can also add the library directory to the MATLAB path using the following
commands:addpath ('library_folder')
savepath
Where:
-
'library_folder' -
savepathis a string that saves the current search path to pathdef.m.
rmpath ('library_folder')
savepath
To view the new library in the Library Browser, right-click on the left side of the window, then select Refresh Library Browser. This loads the library into the tool. You can now view the imported blocks and drag and drop them into your models.