Main Content

createElementLink

Class: slreportgen.webview.EmbeddedWebViewDocument
Namespace: slreportgen.webview

Element link in embedded web view report

Syntax

elemLink = createElementLink(wvdoc,ehandle,domlabel)

Description

elemLink = createElementLink(wvdoc,ehandle,domlabel) links a DOM object in an embedded web view document pane to an element anchor in the Simulink® web view. The generated elemlink DOM object is of the same type as domlabel or, if domlabel is a string, the DOM object is an mlreportgen.DOM.Text object.

Input Arguments

expand all

Web view document, specified as an slreportgen.webview.WebViewDocument object.

Handle of web view element anchor, specified as a character vector of the path or as an object handle. You can use the getExportDiagrams method to obtain the element paths and handles.

Example: Character vector: 'slrgex_vdp/Mu'. Object handle: get_param('slrgex_vdp/Mu','handle')

DOM object from which to link, specified as a valid DOM object or as a character vector. If you enter a character vector, an mlreportgen.DOM.Text object is created.

Output Arguments

expand all

Examples

expand all

This example shows how to create links from second level headings and block names in the document pane to the associated diagrams and blocks in the embedded web view.

Write a class called LinkWebView that is a subclass of slreportgen.webview.EmbeddedWebViewDocument. In the fillContent method, use createDiagramLink and createElementLink to create links to the embedded web view.

classdef LinkWebView < slreportgen.webview.EmbeddedWebViewDocument

    methods
        function wvdoc = LinkWebView(reportPath,modelName)
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the fill
            % methods of the report.
            wvdoc@slreportgen.webview.EmbeddedWebViewDocument( ...
                reportPath,modelName);
        end

        function fillContent(wvdoc)
            % Fill the Content hole in the report template with design
            % variable information. Use DOM or Report API methods to
            % create, format, add, and append content to this report.

            [~, handles] = getExportDiagrams(wvdoc);

            n = numel(handles);
            for i = 1:n
                diagHandle = handles{i};
                diagHeading = createDiagramLink(wvdoc, ...
                    diagHandle, ...
                    mlreportgen.dom.Heading(2, ...
                        get_param(diagHandle,'Name')));
                append(wvdoc,diagHeading);

                blockFinder = slreportgen.finder.BlockFinder( ...
                    diagHandle);

                while hasNext(blockFinder)
                    r = next(blockFinder);
                    elemHandle = r.Object;
                    elemHeading = createElementLink(wvdoc, ...
                        elemHandle, ...
                        mlreportgen.dom.Heading(3, ...
                            get_param(elemHandle,'Name')));
                    append(wvdoc,elemHeading);
                end

            end
        end
    end
end

Load the model.

model_name = "sf_car";
load_system(model_name);

Create an object of the LinkWebView class.

wvdoc = LinkWebView("myReport",model_name);

Use the methods in the class to generate the embedded web view report.

open(wvdoc);
fill(wvdoc);

Close the report and open the viewer.

close(wvdoc);
rptview(wvdoc);

More About

expand all

Version History

Introduced in R2017a