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:
- copying the project to the 'tempdir', (such that the reference projects won't be on path)
- opening the copied project and creating the template,
- 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:
- 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.
- 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.