В этом примере показано, как программно создать новый проект и добавить его как ссылочный проект в вашем основном проекте. Это покрывает, как создать проект из командной строки, добавьте файлы и папки, создайте путь к проекту, задайте ярлыки проекта и создайте ссылку на новый проект в другом проекте.
1. Создайте рабочую копию Airframe Example проект и открытый проект. MATLAB® копирует файлы в папку в качестве примера так, чтобы можно было отредактировать их. Используйте currentProject чтобы создать проект возражают из в настоящее время загруженного проекта.
sldemo_slproject_airframe;
Starting: Simulink Building with 'MinGW64 Compiler (C)'. MEX completed successfully.
mainProject = currentProject
mainProject =
Project with properties:
Name: "Airframe Example"
SourceControlIntegration: "Git"
RepositoryLocation: "C:\workSpace\examples\repositories\airframe"
SourceControlMessages: ["Branch status: Normal" "No remote tracking branch" "Current branch: master"]
ReadOnly: 0
TopLevel: 1
Dependencies: [1×1 digraph]
Categories: [1×1 matlab.project.Category]
Files: [1×31 matlab.project.ProjectFile]
Shortcuts: [1×7 matlab.project.Shortcut]
ProjectPath: [1×7 matlab.project.PathFolder]
ProjectReferences: [1×0 matlab.project.ProjectReference]
StartupFiles: [1×0 string]
ShutdownFiles: [1×0 string]
Description: "This is an example project.↵↵Use the "Project Shortcuts" toolstrip tab to find ways of getting started with this project."
RootFolder: "C:\workSpace\examples\airframe"
SimulinkCacheFolder: "C:\workSpace\examples\airframe\work\cache"
ProjectStartupFolder: "C:\workSpace\examples\airframe"
SimulinkCodeGenFolder: "C:\workSpace\examples\airframe\work\codegen"
The Airframe Example проект является проектом верхнего уровня (TopLevel: 1) без projects (ProjectReferences: [1x0])., на который ссылаются,
2. Создайте новый проект под названием Wind Gust Library. Airframe проект будет использовать Wind Gust Library через ссылку проекта.
a. Создайте пустой проект и установите название проекта.
windGustFolder = fullfile(mainProject.RootFolder, "refs", "Wind Gust Library"); windGust = matlab.project.createProject(windGustFolder); windGust.Name = "Wind Gust Library";
b. Переместите wind_gust_lib.slx от основного проекта до новой папки, и добавляют его в Wind Gust Library проект. Затем удалите файл из Airframe Example проект.
movefile("..\..\models\wind_gust_lib.slx"); addFile(windGust, "wind_gust_lib.slx"); reload(mainProject); removeFile(mainProject,"models\wind_gust_lib.slx");
c. Добавьте Wind Gust Library корневая папка проекта к Wind Gust Library путь к проекту. Это делает файлы доступными когда Airframe Example проект или любой проект это ссылается на Wind Gust Library проект загружается.
reload(windGust); addPath(windGust, windGust.RootFolder);
d. Создайте Wind Gust Library ярлык проекта.
shortcut = addShortcut(windGust, "wind_gust_lib.slx"); shortcut.Group = "Top Level Model";
3. Добавьте новый Wind Gust Library проект к Airframe Example проект как ссылка проекта. Это позволяет Airframe Example проект просмотреть, отредактируйте и петляйте в Wind Gust Library проект.
reload(mainProject); addReference(mainProject, windGust)
ans =
ProjectReference with properties:
Project: [1×1 matlab.project.Project]
File: "C:\workSpace\examples\airframe\refs\Wind Gust Library"
StoredLocation: "refs/Wind Gust Library"
Type: "Relative"
Основной проект Airframe Example ссылается на Wind Gust Library сохраненный в "../refs/Wind Gust Library".
4. Используйте ProjectReferences метод, чтобы запросить Wind Gust Library project.
mainProject.ProjectReferences(1).Project
ans =
Project with properties:
Name: "Wind Gust Library"
SourceControlIntegration: ""
RepositoryLocation: ""
SourceControlMessages: [1×0 string]
ReadOnly: 1
TopLevel: 0
Dependencies: [1×1 digraph]
Categories: [1×1 matlab.project.Category]
Files: [1×1 matlab.project.ProjectFile]
Shortcuts: [1×1 matlab.project.Shortcut]
ProjectPath: [1×1 matlab.project.PathFolder]
ProjectReferences: [1×0 matlab.project.ProjectReference]
StartupFiles: [1×0 string]
ShutdownFiles: [1×0 string]
Description: ""
RootFolder: "C:\workSpace\examples\airframe\refs\Wind Gust Library"
Wind Gust Library проект не является проектом верхнего уровня (TopLevel: 0). На это ссылаются проект верхнего уровня Airframe Example (TopLevel: 1).