how can i access to the export button on the architecture views of the system composer, using code?
4 views (last 30 days)
Show older comments
I want to access the "export" button that is in the toolstrip of the architecture view tab, through code. Is it possible that with code or some function, I can export a view as if I had pressed the "export" button?
I have tried creating a report, but the images of the view are bad quality, it does not get the same quality and page orientation as if i clicked the export button.
1 Comment
Saurav
on 19 Aug 2024
As of now, this feature isn't supported by MATLAB to export the architecture view programmatically.
Accepted Answer
More Answers (1)
Malay Agarwal
on 19 Aug 2024
You can use the Simulink Report Generator toolbox (https://www.mathworks.com/products/simulink-report-generator.html) with System Composer APIs to export an architectural view as an image. Please refer to the following example, which demonstrates how to do this: https://www.mathworks.com/help/releases/R2023a/systemcomposer/ug/report-generation-system-architectures.html.
In the "Architecture Views" section of the example (https://www.mathworks.com/help/releases/R2023a/systemcomposer/ug/report-generation-system-architectures.html#ReportGenerationForSystemArchitecturesExample-4), the "systemcomposer.rptgen.finder.ViewFinder" class is used to find all architectural views in the model. It then loops over all the views and adds them to a report. The image in the report is equivalent to the image you get using the Export button.
If you want the resultant PDF to just have the views, you can skip adding any title page, table of contents, sections or chapters. You can then access the "Snapshot" property of each view to append just an image of the view to the report. For example:
% Create a report
rpt = slreportgen.report.Report('OutputPath','SystemModel'+".pdf",...
'CompileModelBeforeReporting',false);
% Change the orientation to landscape
rpt.Layout.Landscape = true;
% TODO - Replace with your model
model = systemcomposer.loadModel("mTestModel");
% Find all the views using "ViewFinder"
view_finder = systemcomposer.rptgen.finder.ViewFinder(model.Name);
% Loop over all the views
while(hasNext(view_finder))
v = next(view_finder);
% Create a Image using the Snapshot property of the view
img = mlreportgen.dom.Image(which(v.Snapshot.Image));
% Change the style to scale the image to the page size
img.Style = {mlreportgen.dom.ScaleToFit};
% Append the image to the report
append(rpt, img);
end
% View the report
rptview(rpt)
The model that I've used in the above code and generated report are attached to the answer.
Please refer to the following resources for more information:
- "slreportgen.report.Report" documentation - https://www.mathworks.com/help/releases/R2023a/rptgenext/ug/slreportgen.report.report-class.html
- "systemcomposer.rptgen.finder.ViewFinder" documentation - https://www.mathworks.com/help/releases/R2023a/systemcomposer/ref/systemcomposer.rptgen.finder.viewfinder-class.html
- "mlreportgen.dom.Image" documentation - https://www.mathworks.com/help/releases/R2023a/rptgen/ug/mlreportgen.dom.image-class.html
- "mlreportgen.dom.ScaleToFit" documenation - https://www.mathworks.com/help/releases/R2023a/rptgen/ug/mlreportgen.dom.scaletofit-class.html
Hope this helps!
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!