how can i access to the export button on the architecture views of the system composer, using code?

79 次查看(过去 30 天)
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.

采纳的回答

Josh Kahn
Josh Kahn 2024-8-19,12:20
编辑:Josh Kahn 2024-8-19,17:29
Thanks for reaching out! The view export resolution with report generator is a known issue that we are investigating. If you send me a private message with your email address, I can get you a workaround.
Josh

更多回答(1 个)

Malay Agarwal
Malay Agarwal 2024-8-19,10:04
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:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by