Main Content

matlab.project.Project

Project object

Description

The matlab.project.Project object represents the currently loaded project. Use the project object to programmatically manipulate the project, interact with source control, and find file dependencies.

Creation

To create a matlab.project.Project object, use the currentProject function to get the currently open project. For example:

proj = currentProject;
If no project is currently open, use the openProject function to load an existing project. For example:
proj = openProject("C:/workSpace/project1/");
To create and open a blank project and get the project object, use the matlab.project.createProject function. For example:
proj = matlab.project.createProject;

Properties

expand all

Project name, specified as a string scalar.

Project description, specified as a string scalar.

Path of project root folder, specified as a string scalar.

This property is read-only.

Top-level status, returned as a logical 1 (true) if the project is a top-level project.

This property is read-only.

Project permission status, returned as a logical 1 (true) if the project has limited permissions when using add, remove, and create object functions. A referenced project status is always read-only to prevent modification.

Project definition file types, specified as an array of DefinitionFilesType objects. Use matlab.project.convertDefinitionFiles to change the current project definition file type programmatically.

This property is read-only.

Source control information, specified as a string array.

Example: "Branch status: Normal" "No remote tracking branch" "Current branch: main"

This property is read-only.

Project repository location, specified as a string scalar.

This property is read-only.

Source control integration type, specified as a string scalar.

Example: "Git"

Paths of project files, specified as an array of ProjectFile objects. This property changes when you add or remove project files. You can use addFile, addFolderIncludingChildFiles, or removeFile to add or remove project files.

Shortcut files for project, specified as an array of Shortcut objects. This property changes when you add or remove shortcut files. You can use addShortcut and removeShortcut to create or remove shortcut files programmatically.

Label categories for project, specified as an array of Category objects. This property changes when you create or remove label categories. You can use createCategory and removeCategory to create and remove label categories programmatically.

Graph of dependencies between project files, specified as a digraph object.

Project startup files, specified as a string array. This property changes when you add or remove startup files. You can use addStartupFile and removeStartupFile to add or remove startup files programmatically.

Project shutdown files, specified as a string array. This property changes when you add or remove shutdown files. You can use addShutdownFile and removeShutdownFile to add or remove shutdown files programmatically.

Project path folders that are added to the MATLAB® path, specified as an array of PathFolder objects.

Paths of referenced projects, specified as an array of ProjectReference objects. This property changes when you add or remove reference projects. You can use addReference and removeReference to add or remove reference projects programmatically.

Path of the project startup folder, specified as a string scalar.

Path of Simulink® cache folder, specified as a string scalar.

Path of Simulink Coder™ code generation folder, specified as a string scalar.

Path of dependency analysis cache file, specified as a string scalar.

Object Functions

expand all

currentProjectGet current project
openProjectLoad an existing project
isLoadedDetermine if project is loaded
reloadReload project
closeClose project
exportExport project to archive
matlab.project.createProjectCreate blank project
matlab.project.convertDefinitionFilesChange definition file type of project
matlab.project.deleteProjectStop folder management and delete project definition files
matlab.project.loadProjectLoad project
matlab.project.rootProjectGet root project
addFileAdd file or folder to project
addFolderIncludingChildFilesAdd folder and child files to project
removeFileRemove file or folder from project
addPathAdd folder to project path
removePathRemove folder from project path
addReferenceAdd referenced project to project
listAllProjectReferencesList all projects in reference hierarchy of current project
removeReferenceRemove project reference
addStartupFileAdd startup file to project
addShutdownFileAdd shutdown file to project
removeStartupFileRemove startup file from project startup list
removeShutdownFileRemove shutdown file from project shutdown list
addShortcutAdd shortcut to project
removeShortcutRemove shortcut from project
addLabelAttach label to project file
createLabelCreate project label
removeLabelRemove label from project
findLabelGet project file label
createCategoryCreate category of project labels
findCategoryFind project category of labels
removeCategoryRemove project category of labels
findFileFind single project file by name
listModifiedFilesList modified files in project
listRequiredFilesGet files required by specified project files
listImpactedFilesGet files impacted by changes to specified project files
listAllProjectReferencesList all projects in reference hierarchy of current project
refreshSourceControlUpdate source control status of project files
runChecksRun all project checks
updateDependenciesUpdate project dependencies
matlab.project.isUnderProjectRootDetermine whether file or folder is under project root folder
matlab.project.isFileInProjectDetermine whether file or folder belongs to project

Examples

collapse all

Open the Times Table App project and use currentProject to get a project object that you can manipulate programmatically.

openExample("matlab/TimesTableProjectExample")
proj = currentProject
proj = 

  Project with properties:

                        Name: "Times Table App"
    SourceControlIntegration: "Git"
          RepositoryLocation: "C:\workSpace\examples\repositories\TimesTableApp"
       SourceControlMessages: ["Branch status: Normal"    "Current branch: main"    "No remote tracking branch"]
                    ReadOnly: 0
                    TopLevel: 1
                Dependencies: [1×1 digraph]
                  Categories: [1×1 matlab.project.Category]
                       Files: [1×15 matlab.project.ProjectFile]
                   Shortcuts: [1×4 matlab.project.Shortcut]
                 ProjectPath: [1×3 matlab.project.PathFolder]
           ProjectReferences: [1×0 matlab.project.ProjectReference]
                StartupFiles: [1×0 string]
               ShutdownFiles: [1×0 string]
         DefinitionFilesType: FixedPathMultiFile
                 Description: "This example project contains the source code and tests for a simple educational app. ↵↵Use the "Project Shortcuts" toolstrip tab to find ways of getting started with this project."
                  RootFolder: "C:\workSpace\examples\TimesTableApp"
        ProjectStartupFolder: "C:\workSpace\examples\TimesTableApp"
         DependencyCacheFile: ""
       SimulinkCodeGenFolder: ""
         SimulinkCacheFolder: ""

Open the Times Table App project and create a project object.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Find the functions that you can execute on the project object.

methods(proj)
Methods for class matlab.project.Project:

addFile                       export                        removeCategory                
addFolderIncludingChildFiles  findCategory                  removeFile                    
addPath                       findFile                      removePath                    
addReference                  isLoaded                      removeReference               
addShortcut                   listAllProjectReferences      removeShortcut                
addShutdownFile               listImpactedFiles             removeShutdownFile            
addStartupFile                listModifiedFiles             removeStartupFile             
addprop                       listRequiredFiles             runChecks                     
close                         refreshSourceControl          updateDependencies            
createCategory                reload                        

Methods of matlab.project.Project inherited from handle.                      

Get a project object, and examine its properties.

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Examine the project files.

files = proj.Files
files = 

  1×14 ProjectFile array with properties:

    Path
    Labels
    Revision
    SourceControlStatus

Examine the labels of the 13th file.

proj.Files(13).Labels
ans = 

  Label with properties:

            File: "C:\workSpace\examples\TimesTableApp\utilities\runTheseTests.m"
        DataType: 'none'
            Data: []
            Name: "Design"
    CategoryName: "Classification"

Get a particular file by name.

myfile = findFile(proj,"source/timesTableGame.m")
myfile = 

  ProjectFile with properties:

                   Path: "C:\workSpace\examples\TimesTableApp\source\timesTableGame.m"
                 Labels: [1×1 matlab.project.Label]
               Revision: ""
    SourceControlStatus: Unmodified

Find out what you can do with the file.

methods(myfile)
Methods for class matlab.project.ProjectFile:

addLabel     findLabel    removeLabel  

Version History

Introduced in R2019a