Is there a way to generate a simulink project template programmatically without including referenced projects?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Infinite_king
le 26 Sep 2023
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
- https://in.mathworks.com/help/matlab/ref/matlab.project.createproject.html
- https://in.mathworks.com/help/matlab/ref/matlab.project.project.addfile.html
- https://in.mathworks.com/help/matlab/ref/openproject.html
- https://in.mathworks.com/help/matlab/ref/matlab.project.project.removereference.html
- https://in.mathworks.com/help/simulink/slref/simulink.exporttotemplate.html
Hope this is helpful
1 commentaire
Eugene Ofori
le 29 Sep 2023
Modifié(e) : Eugene Ofori
le 9 Nov 2023
Catégories
En savoir plus sur Using MATLAB Projects in Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!