Main Content

ssc_build

Build custom library from collection of Simscape files

Description

example

ssc_build(package) generates a custom Simscape™ library file from the specified package, package. Call ssc_build from the package parent directory, that is, from the directory containing the top-level package directory. For more information on package directory structure, see Organizing Your Simscape Files.

When you call ssc_build with one argument, the library file is named package_lib and is located in the package parent directory. The library contains all the sublibraries and blocks generated from the Simscape files (either source or protected) located in the package and its subdirectories. Simscape protected files have higher precedence than the source files when you build a library. If both the protected and the source files are present in the package and the source files are newer than the protected files, ssc_build uses the protected files to build the library, but issues a warning.

example

ssc_build(package,'-output',outputlibrary) generates a custom Simscape library file from the specified package, package, with outputlibrary defining the library file name and location. This syntax uses a name-value argument pair, where '-output' is the name of the optional argument and outputlibrary is the argument value. The function implements partial argument name matching, therefore specifying '-o' as the argument name also works.

example

ssc_build package is the command form of the syntax. Command form requires fewer special characters. You do not need to type parentheses or enclose the input in single or double quotes. Separate inputs with spaces instead of commas.

For example, to build a package named +MyPackage, these statements are equivalent:

ssc_build MyPackage        % command form
ssc_build('MyPackage')     % function form

You can also use command form with the name-value argument pair, described in the previous syntax, as long as the path and name of the output library is a character vector. For example, to build a package named +MyPackage and save the output library as 'C:\Work\MyLibrary', these statements are equivalent:

ssc_build MyPackage -output C:\Work\MyLibrary          % command form
ssc_build('MyPackage','-output','C:\Work\MyLibrary')   % function form

Do not use command form when outputlibrary uses variables, or functions like fullfile, to specify the output library name and location. For more information on the command-function duality, see Command vs. Function Syntax.

ssc_build is a special syntax, with no arguments, that you can use to call the function from inside the package directory structure. It builds a library from the current package, with default library name and location. To specify a different name or location for the output library, call ssc_build from the package parent directory using either the command or the function form of the syntax with the name-value argument pair.

Examples

collapse all

Suppose your top-level package directory, where you store your Simscape files, is named +SimscapeCustomBlocks and is located in C:\Work\MyLibraries.

To generate a custom block library, change your current working directory to C:\Work\MyLibraries. Then, at the MATLAB® Command prompt, type:

ssc_build('SimscapeCustomBlocks');

You can also use the command form of this syntax, which requires fewer special characters:

ssc_build SimscapeCustomBlocks;

This command generates a Simulink® model file called SimscapeCustomBlocks_lib in the package parent directory, C:\Work\MyLibraries (that is, in the same directory that contains your +SimscapeCustomBlocks package).

Suppose your top-level package directory, where you store your Simscape files, is named +CustomElectricalBlocks and is located in C:\Work. You want to generate a custom block library from this package, place it in C:\Work\MyLibraries, and give it a shorter and more meaningful name, CustomDiodes. You do this by providing the name-value argument pair to the ssc_build function.

To generate the custom block library, change your current working directory to C:\Work. Then, at the MATLAB Command prompt, type:

ssc_build('CustomElectricalBlocks','-output','C:\Work\MyLibraries\CustomDiodes')
Generating Simulink library 'CustomDiodes' in the output directory 'C:\Work\MyLibraries' ...

This function call generates a Simulink model file called CustomDiodes.slx in the specified directory. Add the C:\Work\MyLibraries directory to the MATLAB path to facilitate using these custom blocks in various models.

Suppose your package with source files is located in a read-only directory. For example, the +BatteryPack package is used in the Lithium-Ion Battery Pack With Fault Using Arrays example. For more information on this package, see Case Study — Battery Pack with Fault Using Arrays.

To generate a custom block library from the +BatteryPack package, you must specify a location for the output library other than the read-only parent directory of the package. You do this by providing the name-value argument pair to the ssc_build function. In this example, the output directory name is a character vector, which allows you to use the command form of the syntax.

Change your current working directory to the directory containing the +BatteryPack package.

cd(matlabroot)
cd toolbox/physmod/simscape/simscapedemos 

At the MATLAB Command prompt, type:

ssc_build BatteryPack -output C:\Work\BatteryPack_lib
Generating Simulink library 'BatteryPack_lib' in the output directory 'C:\Work' ...

This command generates a Simulink model file called BatteryPack_lib in the specified output directory, C:\Work.

You can also take advantage of the partial argument name matching and shorten the command syntax even more:

ssc_build BatteryPack -o C:\Work\BatteryPack_lib

This command is equivalent to the previous one.

Input Arguments

collapse all

Name of package containing Simscape files, specified as a character vector or a string scalar and located in the directory from which you call the ssc_build function. package is the name of the top-level package directory without the leading + character. When you call ssc_build using the command syntax, do not use quotes around package. For more information on the command-function duality, see Command vs. Function Syntax.

Example: ssc_build MyPackage is the command syntax to build a library from the package +MyPackage. The equivalent function syntax is ssc_build('MyPackage').

Name and location of the block library file generated from the package, specified as a character vector or a string scalar. When you call ssc_build using the function syntax, you can also use MATLAB variables and functions, such as fullfile or genpath, to specify the path to the library file.

If you specify a file name without the path, the library is generated in your current working directory. When you specify the file name, you can include the file extension, .slx, or omit it.

Example: fullfile(tempdir,'MyLibrary.slx') with function syntax, you can use MATLAB variables and functions to specify the path.

Introduced in R2008b