Is there a way to generate a simulink project template programmatically without including referenced projects?

조회 수: 3 (최근 30일)
I am trying to generate a simulink project template programmatically without including reference projects. This option is available when using the Share -> Simulink Project method.
I've tried this with the Simulink.exportToTemplate method but the documentation doesn't describe a parameter to not include referenced projects. Is there a way to achieve this?

채택된 답변

Eugene Ofori
Eugene Ofori 2023년 12월 19일
편집: Eugene Ofori 2023년 12월 19일
I found a workaround. The template keeps referring to their reference projects but won't package them into the template if the reference projects can't be found on the specified path when creating it. So my method involves:
  1. copying the project to the 'tempdir', (such that the reference projects won't be on path)
  2. opening the copied project and creating the template,
  3. cleaning up by deleting the copied content.
oldpath = path;
newroot = fullfile(tempdir, 'SimulinkTempDump')
og_proj_root = folder_nm;
mkdir(newroot);
copyfile(og_proj_root, newroot)
temp_proj = openProject(newroot);
Simulink.exportToTemplate(...
temp_proj, ...
template_path, ...
'Description', description, ...
'Title', template_nm);
%% Cleanup
close(temp_proj);
openProject(og_proj_root);
path(oldpath) %replace the old path so we can delete our temp folder
%% Remove Temp
if exist(newroot, 'dir')
rmdir(newroot, 's');
end
Note:
  1. Since the reference projects are not successfully opening on the copied project, I'm not sure what issues this may cause when creating the template.
  2. If your project uses absolute paths for its references or the copied project (using relative paths) can still find the reference projects, I think your reference projects will still be packaged with your template.

추가 답변 (1개)

Infinite_king
Infinite_king 2023년 9월 26일
Hi,
I understand that you want to generate a project template without including project references by using “Simulink.exportToTemplate” function.
One way of achieving this is to remove the referenced projects from the main project using “removeReference” function and then generating a project template using “Simulink.exportToTemplate” function.
Please refer the below template code,
%create a project and add the model
proj = matlab.project.createProject(ProjectPath); % Replace the ProjectPath with the desired path where you want to create the project
proj.Name = "ProjectName"; % rename the project
addFile(proj,'modelName.slx') % add the required model to the project
% or Open the project
proj = openProject(ProjectPath); % replace the ProjectPath with the path of the project
removeReference(proj,PathtoReferencedProject); % give path of refernced project to remove the reference from the project
templatefile = Simulink.exportToTemplate(proj,TemplateName); % Converting the project to a template
For more information on how to create project, add files and create project template, refer the following resources
  1. https://in.mathworks.com/help/matlab/ref/matlab.project.createproject.html
  2. https://in.mathworks.com/help/matlab/ref/matlab.project.project.addfile.html
  3. https://in.mathworks.com/help/matlab/ref/openproject.html
  4. https://in.mathworks.com/help/matlab/ref/matlab.project.project.removereference.html
  5. https://in.mathworks.com/help/simulink/slref/simulink.exporttotemplate.html
Hope this is helpful
  댓글 수: 1
Eugene Ofori
Eugene Ofori 2023년 9월 29일
편집: Eugene Ofori 2023년 11월 9일
Hi, thanks for the response. I saw the removeReference function but it doesn't seem to be what I was looking for. The function seems to alter the project and remove the references. The outcome I basically want and currently get through creating templates using the GUI, is when I create a new project from the template, it doesn't generate the external references but it still looks for them in the same relative path as the original project.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dependency Analysis에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by