Print all Sub charts in a Stateflow model to individual files

7 views (last 30 days)
Hello Matlab Forum,
I'm having an issue printing sub charts to file. I essentially want to open all Sub Charts in a Stateflow diagram and print them individually to pdf files for a large model, I thought this would be easy, but it only seems easy to work for charts. Nothing more than opening up all charts and doing a automatic "Print -> Print to File -> PDF"
The following (using a matlab example will work for a chart but not for a sub chart) if you pass in a sub chart on a state it errors and falls over, in this case I would pass '-isa' a 'Stateflow.State' but ensure it is a sub chart too.
Any ideas/ alternates greatly appreciated, I've been stuck on this a while. I might have to resort to producing a docx through the Reporting API and parsing through that in VBA, or using the clipboard somehow maybe, don't really want to open and close a ton of windows though.
chart = find(sfroot, '-isa','Stateflow.Chart','Name','Gear_logic');
chart.fitToView;
chartHandle = get_param(string(chart.Path) +'/','Handle');
sfprint(chartHandle, 'jpg')
I can display charts on screen as shown below, but I can't export them to file using print of sfprint, what am I missing: -
chartColl = find(sfroot, '-isa', 'Stateflow.State', '-and', 'IsSubchart', 1 );
for i=1 : length(chartColl)
chart= chartColl(i,1);
%chart.fitToView;
chart.view;
print ('c:\temp\testy.pdf','pdf');
%print '-dpdf' + ' C:\Temp\' + string(chart.id) + '.pdf';
%dump the image/ file in the clipboard somehow
%sfprint(gcb,'pdf', 'C:\Temp\' + string(chart.id) + '.pdf',0);
%chtHand= get_param(string(chart.Path) + '/', 'Handle');
%sfprint(chtHand,'pdf', 'C:\Temp\' + string(chart.id) + '.pdf');
end
Cheers for any help
Richard

Accepted Answer

Nicolas Schoonbroodt
Nicolas Schoonbroodt on 28 Oct 2020
Hi Richard,
I'm not quite sure that this is what your are looking for, but maybe this could help. You don't need to pass a handle to sfprint, you can directly pass the object, and I think that you could simply do this:
allSubcharts = find(sfroot, 'IsSubchart',1);
for idx=1:length(allSubcharts)
sfprint(allSubcharts(idx), 'jpg');
end
  1 Comment
Richard Good
Richard Good on 28 Oct 2020
For some reason the internet and the help pointed me at saveas which didn't work for me. Nothing pointed me at sfprint until I raised a case. That came back using the handle technique so I didn't twig I could just use an object. Thanks for the correction!!

Sign in to comment.

More Answers (0)

Categories

Find more on Complex Logic in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!