MATLAB Examples

Creating Simulink Projects Programmatically

This example shows how to use the Simulink Project API to create and set up a new Simulink Project. It shows how to create a Simulink Project from the command line, add files and folders, set up the project path, define project shortcuts and create a reference to the new project in another project.

Contents

Setting Up the Example Files

Run the following commands to create a working copy of the project files.

Simulink.ModelManagement.Project.projectDemo('airframe_api', [], true);
Initializing: Project Path
Identifying shadowed project files
Initializing: Project Path
Setting up working folders
Identifying shadowed project files

Create the Wind Gust Project

The following commands will create the wind gust project. This project contains a library and a data dictionary which will be used by the top level project through a project reference.

Create the project and set the project name.

mainProject = slproject.getCurrentProject();

windGustFolder = fullfile(mainProject.RootFolder, '..', 'refs', 'Wind Gust Library');
windGust = slproject.create(windGustFolder);
windGust.Name = 'Wind Gust Library';

% Add the files and folders to the new project.

addFolderIncludingChildFiles(windGust, 'data');
addFile(windGust, 'wind_gust_lib.slx');

% Add folders to the project path
addPath(windGust, windGust.RootFolder);
addPath(windGust, 'data');

% Define the project shortcuts.

shortcut = addShortcut(windGust, 'wind_gust_lib.slx');
shortcut.Group = 'Top Level Model';
Closing Project Models
Clearing: Project Path
Closing working folders
Closing Project Models
Clearing: Project Path
Initializing: Project Path
Setting up working folders
Identifying shadowed project files

Add a Project Reference

The following commands will add the new Wind Gust Library project to the top level project as a project reference.

reload(mainProject);
addReference(mainProject, windGust);
Closing Project Models
Clearing: Project Path
Closing working folders
Initializing: Project Path
Identifying shadowed project files
Initializing: Project Path
Identifying shadowed project files
Initializing: Project Path
Setting up working folders
Identifying shadowed project files

Further Information

Referenced Projects