Best way to makeSvg() for a group part so all its children render too

Hi,

I’m using the following code to download an SVG file of the current digram.selection part. It works just fine for all part types, except for groups. When the selected part is a group, (which in my case is a simple rectangle containing parts), all I get in the SVG is the rectangle of the group, not the child parts of the group. My group can also contain other groups.

So, is there a method I can call on my outermost group that will return a flat list of all the parts in that group, recursively? So I can pass that flat array to makeSvg(). Or do I have to do this myself?




function downloadSVGForSelection(scaleSize) {
    if (myDiagram.selection.toArray().length > 0) {
        myPartsList = new go.List();
        myDiagram.selection.each(function (part) {
            if (part instanceof go.Node) {
                myPartsList.add(part)
            }
        });
        var svg = myDiagram.makeSvg({ scale: scaleSize, background: "white", parts: myPartsList })
        var svgstr = new XMLSerializer().serializeToString(svg);
        var blob = new Blob([svgstr], { type: "image/svg+xml" });
        downloadSVGCallback(blob);
    } else {
        alert("Please select a node to print")
    }
}

function downloadSVGCallback(blob) {
    let dt = new Date().toISOString().slice(0, 16).replace(":", "-")
    var url = window.URL.createObjectURL(blob);
    let procedure = getProcedureID(false)
    var filename = "procedure_" + procedure + "_time_" + dt + ".svg";

    var a = document.createElement("a");
    a.style = "display: none";
    a.href = url;
    a.download = filename;

    // IE 11
    if (window.navigator.msSaveBlob !== undefined) {
        window.navigator.msSaveBlob(blob, filename);
        return;
    }


    document.body.appendChild(a);
    requestAnimationFrame(function () {
        a.click();
        window.URL.revokeObjectURL(url);
        document.body.removeChild(a);
    });
}

Call https://gojs.net/latest/api/symbols/Group.html#findSubGraphParts to get a collection of all of the (possibly indirect) members of a Group.