Main Content

createElementLink

Class: slreportgen.webview.EmbeddedWebViewDocument
Package: slreportgen.webview

Element link in embedded Web view report

Syntax

elemLink = createElementLink(wvdoc,ehandle,domlabel)

Description

elemLink = createElementLink(wvdoc,ehandle,domlabel) updates a DOM object in an embedded Web view Document panel so that it links to an element anchor in the Simulink® Web view. The DOM object is of the same type as domlabel or, if domlabel is a string, an mlreportgen.DOM.Text object is created.

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: 'vdp/mu'. Object handle: get_param('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

Use CreateElementLink to create links from block names in the document pane to blocks in the diagram in the embedded web view. This example also uses createDiagramLink to create links from level two headings in the document pane to diagrams in the embedded web view.

Write a class, ExampleWebView, that is a subclass of slreportgen.webview.EmbeddedWebViewDocument. Use CreateElementLink and createDiagramLink in the fillContent method.

classdef ExampleWebView < slreportgen.webview.EmbeddedWebViewDocument
        
    methods
        function wvdoc = ExampleWebView(reportPath,modelName)
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the
            % report's fill methods.
            wvdoc@slreportgen.webview.EmbeddedWebViewDocument(reportPath,modelName);
        end
        
        function fillContent(wvdoc)
            % Fill the Content hole in the report template with design
            % variable information. You can 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

Create an object of the ExampleWebView class and use its methods to generate the embedded web view report.

model = 'vdp';
open_system(model);
wvdoc = ExampleWebView('myReport',model);
open(wvdoc);
fill(wvdoc);
close(wvdoc);
rptview(wvdoc);

More About

expand all

Introduced in R2017a