プログラムによるプロジェクトの作成と参照
この例では、プログラムで新しいプロジェクトを作成し、それを参照プロジェクトとしてメインのプロジェクトに追加する方法を説明します。コマンド ラインからのプロジェクトの作成、ファイルとフォルダーの追加、プロジェクト パスの設定、プロジェクトのショートカットの定義、および別プロジェクトの新しいプロジェクトへの参照の作成方法を説明します。
例のファイルの設定
機体のプロジェクトを開きます。currentProject
を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。
openExample("simulink/AirframeProjectWithOneReferencedProjectExample")
mainProject = currentProject
mainProject = Project with properties: Name: "Airframe Example" Description: "This example project demonstrates the Project referencing feature." RootFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/airRef" TopLevel: 1 ReadOnly: 0 DefinitionFilesType: FixedPathMultiFile SourceControlIntegration: "" RepositoryLocation: "" Files: [1×22 matlab.project.ProjectFile] Shortcuts: [1×2 matlab.project.Shortcut] Categories: [1×1 matlab.project.Category] Dependencies: [1×1 digraph] StartupFiles: [1×0 string] ShutdownFiles: [1×0 string] ProjectPath: [1×4 matlab.project.PathFolder] ProjectReferences: [1×1 matlab.project.ProjectReference] DependencyCacheFile: "" ProjectStartupFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/airRef" SimulinkCacheFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/airRef/work/cache" SimulinkCodeGenFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/airRef/work/codegen"
Airframe Example
プロジェクトは、参照プロジェクト (ProjectReferences: [1x1]
) を 1 つもつ最上位レベル プロジェクト (TopLevel: 1
) です。
新規プロジェクトの作成
Wind Gust Library
と呼ばれる新規プロジェクトを作成します。Airframe
プロジェクトはプロジェクト参照を通じて Wind Gust
Library
を使用します。
1. 空のプロジェクトを作成してプロジェクト名を設定します。
windGustFolder = fullfile(mainProject.RootFolder,"..","WindGustLibrary"); windGust = matlab.project.createProject(windGustFolder); windGust.Name = "Wind Gust Library";
2. data
フォルダーと wind_gust_lib.slx
ファイルを Wind Gust
Library
プロジェクトに追加します。
addFolderIncludingChildFiles(windGust,"data"); addFile(windGust,"wind_gust_lib.slx");
3. data
フォルダーと Wind Gust Library
プロジェクト ルート フォルダーを Wind Gust Library
プロジェクト パスに追加します。これにより、Airframe Example
プロジェクトまたは Wind Gust Library
プロジェクトを参照する任意のプロジェクトが読み込まれるとファイルが利用可能になります。
addPath(windGust,"data");
addPath(windGust,windGust.RootFolder);
4. Wind Gust Library
プロジェクト ショートカットを作成します。
shortcut = addShortcut(windGust,"wind_gust_lib.slx"); shortcut.Group = "Top Level Model";
プロジェクト参照の追加
新しい 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: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary" StoredLocation: "../WindGustLibrary" Type: "Relative"
メインのプロジェクト Airframe Example
は "../refs/Wind Gust Library"
に格納された Wind Gust Library
を参照します。
ProjectReferences
メソッドを使用して Wind Gust Library
プロジェクトをクエリします。
mainProject.ProjectReferences(2).Project
ans = Project with properties: Name: "Wind Gust Library" Description: "" RootFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary" TopLevel: 0 ReadOnly: 1 DefinitionFilesType: FixedPathMultiFile SourceControlIntegration: "" RepositoryLocation: "" Files: [1×3 matlab.project.ProjectFile] Shortcuts: [1×1 matlab.project.Shortcut] Categories: [1×1 matlab.project.Category] Dependencies: [1×1 digraph] StartupFiles: [1×0 string] ShutdownFiles: [1×0 string] ProjectPath: [1×2 matlab.project.PathFolder] ProjectReferences: [1×0 matlab.project.ProjectReference] DependencyCacheFile: "" ProjectStartupFolder: "/tmp/Bdoc25a_2974004_3521128/tpd9b8b565/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary" SimulinkCacheFolder: "" SimulinkCodeGenFolder: ""
Wind Gust Library
プロジェクトは最上位プロジェクト (TopLevel: 0
) ではありません。これは最上位プロジェクト Airframe Example
(TopLevel: 1
) によって参照されます。
プロジェクトを閉じる
プロジェクトを閉じてシャットダウン スクリプトを実行し、未保存のファイルを確認します。
close(mainProject)