Main Content

Building Custom Block Libraries

Workflow Overview

To generate a custom block library from Simscape™ component files, follow these steps:

  1. Organize your Simscape files. Simscape files must be saved in package directories. The package hierarchy determines the resulting library structure.

  2. Optionally, provide source protection. If you want to share your models with customers without disclosing the component or domain source, you can generate Simscape protected files and share those.

  3. Build the custom block library. You can use either the regular Simscape source files or Simscape protected files to do this. Each top-level package generates a separate custom Simscape block library.

Once you generate the custom Simscape library, you can open it and drag the customized blocks from it into your models.

Organizing Your Simscape Files

Simscape files must be saved in package directories. The important points are:

  • The package directory name must begin with a + character.

  • The rest of the package directory name (without the + character) must be a valid MATLAB® identifier.

  • The package directory's parent directory must be on the MATLAB path.

Each package where you store your Simscape files generates a separate custom block library.

Package directories may be organized into subdirectories, with names also beginning with a + character. After you build a custom block library, each such subdirectory will appear as a sublibrary under the top-level custom library.

For example, you may have a top-level package directory, named +SimscapeCustomBlocks, and it has three subdirectories, +Electrical, +Hydraulic, and +Mechanical, each containing Simscape files. By default, the custom block library generated from this package will be called SimscapeCustomBlocks_lib (you can specify a different name). The library will have three sublibraries with names corresponding to the package subdirectories (Electrical, Hydraulic, and Mechanical). For information on building custom block libraries, see Converting Your Simscape Files.

Using Source Protection for Simscape Files

If you need to protect your proprietary source code when sharing the Simscape files, use one of the following commands to generate Simscape protected files:

  • ssc_protect — Protects individual files and directories. Once you encrypt the files, you can share them without disclosing the component or domain source. Use them, just as you would the Simscape source files, to build custom block libraries with the ssc_build command.

  • ssc_mirror — Creates a protected copy of a whole package in a specified directory. Setting a flag lets you also build a custom block library from the protected files and place it in the mirror directory, thus eliminating the need to run the ssc_build command. Use the ssc_mirror command to quickly prepare a whole package for sharing with your customers, without disclosing the component or domain source.

Unlike Simscape source files, which have the extension .ssc, Simscape protected files have the extension .sscp and are not humanly-readable. You can use them, just as the Simscape source files, to build custom block libraries. Protected files have to be organized in package directories, in the same way as the Simscape source files. For information on organizing your files, see Organizing Your Simscape Files. For information on building custom block libraries, see Converting Your Simscape Files.

Converting Your Simscape Files

After you have created the textual component files and organized them in package directories, you need to convert them into Simscape blocks to be able to use them in block diagrams. You do this by running the ssc_build command on the top-level package directory containing your Simscape files. The package may contain either the regular Simscape source files or Simscape protected files.

For example, you may have a top-level package directory, where you store your Simscape files, named +SimscapeCustomBlocks. You can generate a custom block library either from the package parent directory, or from a directory inside the package. From the package parent directory, at the MATLAB command prompt, type:

ssc_build SimscapeCustomBlocks;

Note

The package directory name begins with a leading + character, whereas the argument to ssc_build must omit the + character.

This command generates a Simulink® model file called SimscapeCustomBlocks_lib in the parent directory of the top-level package (that is, in the same directory that contains your +SimscapeCustomBlocks package). Because this directory is on the MATLAB path, you can open the library by typing its name at the MATLAB command prompt. In our example, type:

SimscapeCustomBlocks_lib 

The model file generated by running the ssc_build command is the custom Simscape library containing all the sublibraries and blocks generated from the Simscape files located in the top-level package. Once you open the custom Simscape library, you can drag the customized blocks from it into your models.

When building a custom library from a package, ssc_build lets you specify a different name and location for the library file than the default ones. For more information, see ssc_build.

Creating Sublibraries

Package directories may be organized into subdirectories, with names also beginning with a + character. After you run the ssc_build command, each such subdirectory will appear as a sublibrary under the top-level custom library. You can customize the name and appearance of sublibraries by using library configuration files.

Note

When you add or modify component files in package subdirectories, you still run the ssc_build command on the top-level package directory. This updates all the sublibraries.

You may have more than one top-level package directory, that is, more than one package directory located in a directory on the MATLAB path. Each top-level package directory generates a separate top-level custom library.

See Also

| |

Related Examples

More About