Creating Projects Programmatically

This example shows how to use the project API to create and set up a new project. It shows how to create a 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.

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);

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 = currentProject;

windGustFolder = fullfile(mainProject.RootFolder, "..", "refs", "Wind Gust Library");
windGust = matlab.project.createProject(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";

Add a Project Reference

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

addReference(mainProject, windGust);

Further Information

Referenced Projects