Documentation

slproject.getCurrentProjects

List all top-level Simulink projects

Syntax

projects = slproject.getCurrentProjects

Description

example

projects = slproject.getCurrentProjects returns a list of all top-level projects open in Simulink® Project. 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.

sldemo_slproject_airframe
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.

sldemo_slproject_airframe
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.

sldemo_slproject_airframe
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.mdl')
myfile = 

  ProjectFile with properties:

   Path:  'C:\Temp\airframe\models\AnalogControl.mdl'
    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 Simulink 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 Simulink Project Tool. Use simulinkproject to open projects and explore projects interactively. Use slproject.getCurrentProjects for project automation scripts.

Introduced in R2016a

Was this topic helpful?