|
1 | | -function openFile(filename) |
2 | | -% Opens a script file or a model file in the project. |
3 | | -% Before opening the file, this script opens the Project if not open. |
4 | | - |
5 | | -% Copyright 2021 The MathWorks, inc. |
6 | | - |
7 | | -arguments |
8 | | - filename (1,1) string = "HEV_main_script.mlx" |
9 | | -end |
10 | | - |
11 | | -thisProjectFile = "HybridElectricVehicle.prj"; |
12 | | -thisProjectName = "Simscape Hybrid Electric Vehicle Model"; |
13 | | - |
14 | | -loaded = ~isempty(matlab.project.rootProject); |
15 | | -if loaded |
16 | | - currPrj = currentProject; |
17 | | - if currPrj.Name ~= thisProjectName |
18 | | - error(sprintf("This file must first load the project: " + thisProjectName + "\n" ... |
19 | | - + "But another project is currently open: " + currPrj.Name + "\n" ... |
20 | | - + "To use this file, please close the currenly open project.")) |
21 | | - end |
22 | | -else |
23 | | - disp("Opening project: " + thisProjectFile) |
24 | | - openProject(thisProjectFile); |
25 | | -end |
26 | | - |
27 | | -if endsWith(filename, {'.m', '.mlx'}) |
28 | | - disp("Opening script: " + filename) |
29 | | - edit(filename) |
30 | | -elseif endsWith(filename, {'.slx', '.mdl'}) |
31 | | - disp("Opening model: " + filename) |
32 | | - open_system(filename) |
33 | | -else |
34 | | - error('Unknown file type: %s', filename) |
35 | | -end |
36 | | - |
37 | | -end |
| 1 | +function openFile(filename) |
| 2 | +% Opens a script file or a model file in the project. |
| 3 | +% Before opening the file, this script opens the Project if not open. |
| 4 | + |
| 5 | +% Copyright 2021 The MathWorks, inc. |
| 6 | + |
| 7 | +arguments |
| 8 | + filename (1,1) string = "HEV_main_script.mlx" |
| 9 | +end |
| 10 | + |
| 11 | +thisProjectFile = "HybridElectricVehicle.prj"; |
| 12 | +thisProjectName = "Simscape Hybrid Electric Vehicle Model"; |
| 13 | + |
| 14 | +loaded = ~isempty(matlab.project.rootProject); |
| 15 | +if loaded |
| 16 | + currPrj = currentProject; |
| 17 | + if currPrj.Name ~= thisProjectName |
| 18 | + error(sprintf("This file must first load the project: " + thisProjectName + "\n" ... |
| 19 | + + "But another project is currently open: " + currPrj.Name + "\n" ... |
| 20 | + + "To use this file, please close the currenly open project.")) |
| 21 | + end |
| 22 | +else |
| 23 | + disp("Opening project: " + thisProjectFile) |
| 24 | + openProject(thisProjectFile); |
| 25 | +end |
| 26 | + |
| 27 | +if endsWith(filename, {'.m', '.mlx'}) |
| 28 | + disp("Opening script: " + filename) |
| 29 | + edit(filename) |
| 30 | +elseif endsWith(filename, {'.slx', '.mdl'}) |
| 31 | + disp("Opening model: " + filename) |
| 32 | + open_system(filename) |
| 33 | +else |
| 34 | + error('Unknown file type: %s', filename) |
| 35 | +end |
| 36 | + |
| 37 | +end |
0 commit comments