Main Content

slproject.getCurrentProjects

(Not recommended) List all top-level projects

slproject.getCurrentProjects is not recommended. Use matlab.project.rootProject instead. For more information, see Compatibility Considerations.

Description

example

projects = slproject.getCurrentProjects returns a list of all open top-level projects. Currently only one or zero top-level projects can be loaded. Returns an object array of 1 or 0 ProjectManager objects projects that you can use to manipulate the project programmatically. Use slproject.getCurrentProjects for project automation scripts.

If you execute slproject.getCurrentProjects inside a project shortcut, it returns only the project that the shortcut belongs to. If the shortcut belongs to a referenced project, it returns the referenced project.

Examples

collapse all

Open the Airframe project and use slproject.getCurrentProjects to get a project object to manipulate the project at the command line.

openExample('simulink/AirframeProjectExample')
proj = slproject.getCurrentProjects
proj = 

  ProjectManager with properties:

          Name: 'Simulink Project Airframe Example'
           Categories: [1x1 slproject.Category]
            Shortcuts: [1x8 slproject.Shortcut]
          ProjectPath: [1x7 slproject.PathFolder]
    ProjectReferences: [1x0 slproject.ProjectReference]
                Files: [1x30 slproject.ProjectFile]
           RootFolder: 'C:\Work\Simulink\Projects\airframe'

Open the airframe project and create a project object.

openExample('simulink/AirframeProjectExample')
proj = slproject.getCurrentProject
proj = 

  ProjectManager with properties:

          Name: 'Simulink Project Airframe Example'
           Categories: [1x1 slproject.Category]
            Shortcuts: [1x8 slproject.Shortcut]
          ProjectPath: [1x7 slproject.PathFolder]
    ProjectReferences: [1x0 slproject.ProjectReference]
                Files: [1x30 slproject.ProjectFile]
           RootFolder: 'C:\Work\Simulink\Projects\airframe'

Find out what you can do with your project.

methods(proj)
Methods for class slproject.ProjectManager:

addFile                       findCategory        
addFolderIncludingChildFiles  findFile            
close                         isLoaded            
createCategory                listModifiedFiles   
export                        refreshSourceControl


reload
removeCategory
removeFile           

After you get a project object, you can examine project properties.

Open the airframe project and create a project object.

openExample('simulink/AirframeProjectExample')
proj = slproject.getCurrentProjects;

Examine the project files.

files = proj.Files
files = 

  1x30 ProjectFile array with properties:

    Path
    Labels
    Revision
    SourceControlStatus

Examine the labels of the eighth file.

proj.Files(8).Labels
ans = 

  Label with properties:

File: 'C:\Work\airframe\data\system_model.sldd'
            Data: []
        DataType: 'none'
            Name: 'Design'
    CategoryName: 'Classification'

Get a particular file.

myfile = findFile(proj, 'models/AnalogControl.slx')
myfile = 

  ProjectFile with properties:

   Path:  'C:\Temp\airframe\models\AnalogControl.slx'
    Labels: [1x1 slproject.Label]
  Revision: '2'
SourceControlStatus: Unmodified

Find out what you can do with the file.

methods(myfile)
Methods for class slproject.ProjectFile:

addLabel
removeLabel
findLabel

Output Arguments

collapse all

Projects, returned as an object array of 1 or 0 ProjectManager objects. Use the project object to manipulate the currently open project at the command line.

Properties of ProjectManager objects in output argument.

Project PropertyDescription
NameProject name
CategoriesCategories of project labels
ShortcutsShortcut files in project
ProjectPath

Folders that the project puts on the MATLAB® path 

ProjectReferencesFolders that contain referenced projects 
FilesPaths and names of project files
RootFolderFull path to project root folder

Tips

Alternatively, you can use simulinkproject to get a project object, but simulinkproject also opens and gives focus to the Project Tool. Use simulinkproject to open projects and explore projects interactively. Use slproject.getCurrentProjects for project automation scripts.

Version History

Introduced in R2016a

collapse all

R2019a: Simulink project API is not recommended

Starting in R2019a, instead of simulinkproject and related functions, use the currentProject or openProject functions in MATLAB. The Simulink® project API will continue to be supported, but, after R2019a, new features will be available only if you use the new MATLAB project API. There are no plans to remove the Simulink project API at this time.

You can continue to use simulinkproject and related functions listed in methods(simulinkproject). New functions added after R2019a, such as runChecks and listImpactedFiles, do not work with simulinkproject. Use currentProject instead.

The new MATLAB project API is part of the R2019a functionality enabling you to use projects in MATLAB, with or without Simulink. You can now share projects with users who do not have Simulink.