To generate a custom block library from Simscape™ component files, follow these steps:
Organize your Simscape files. Simscape files must be saved in package directories. The package hierarchy determines the resulting library structure.
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.
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.
Simscape files must be saved in package directories. The important points are:
The package directory name must begin with a
The rest of the package directory name (without the
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
and it has three subdirectories,
Mechanical, each containing Simscape files.
The custom block library generated from this package will be called
will have three corresponding sublibraries. For information on building
custom block libraries, see Converting Your 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_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
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.
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
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
To generate a custom block library, at the MATLAB command prompt,
The package directory name begins with a leading
character, whereas the argument to
ssc_build must omit the
This command generates a Simulink® model file called
the parent directory of the top-level package (that is, in the same
directory that contains your
Because this directory is on the MATLAB path, you can open the
library by typing its name at the MATLAB command prompt. In our
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.
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.
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.