Home / Using second stereotype / eaDocX Script examples / Using second stereotype
Structuring your document
(13)
Using second stereotype
function Blocks() {
// Parameters passed to the script:
// ElementGuids - guids of some elements. May be only one.
// Repository
// Tell eaDocX that this is an eaDocX Script
//<Type>eaDocX</Type>
//Script to do special printing of Block class elements using second stereotype
// Get the list of GUIDs from the parameter passed by eaDocX
var elemGuids = ElementGuids.toString();
// Split them up into individual GUIDs for processing
var guids = elemGuids.split(",");
// Create a string to hold the HTML
var outputHTML = "";
var allElements = [];
var allOtherStereotypes = {}; // Dictionary: { otherStereotype: [elements] }
// Step 1: Collect all elements and their "other" stereotypes
for (var i = 0; i < guids.length; i++) {
var guid = guids.trim();
var element = Repository.GetElementByGuid(guid);
if (element !== null) {
allElements.push(element);
var primary = element.Stereotype || "";
var exList = (element.StereotypeEx || "").split(",").map(s => s.trim());
// Find "other" stereotypes and group by them
for (var j = 0; j < exList.length; j++) {
var stereo = exList[j];
if (stereo !== primary && stereo !== "") {
if (!allOtherStereotypes[stereo]) {
allOtherStereotypes[stereo] = [];
}
allOtherStereotypes[stereo].push(element);
}
}
} else {
//maybe do error processing here?
}
}
// Step 2: Build one table per "other" stereotype
var outputHTML = "";
for (var stereo in allOtherStereotypes) {
var elements = allOtherStereotypes[stereo];
outputHTML += "<h3>Group: " + stereo + "</h3>\r\n";
outputHTML += "<table border='1' style='border-collapse: collapse;'>\r\n";
outputHTML += "<tr><th>Name</th><th>Notes</th></tr>\r\n";
for (var i = 0; i < elements.length; i++) {
var el = elements;
outputHTML += "<tr>";
outputHTML += "<td>" + el.Name + "</td>";
outputHTML += "<td>" + (el.Notes || "").replace(/\r?\n/g, "<br>") + "</td>";
outputHTML += "</tr>\r\n";
}
outputHTML += "</table>\r\n<br/>\r\n";
}
return outputHTML;
}
// Call the function
result = Blocks();