Hi,
I am new to Medini tool, I wanted to get No.of events (with ASIL >QM) in the swFTA using java script.Following is the strutre.
I have written but getting zero. Can you please guide me for this?
Here is a skeleton script that can be used to achieve the described use case.
The diagram.js library in its latest version is required, see this article.
The script itself looks like:
// $EXPERIMENTAL$ $STRICT_MODE$ $WARNING_AS_ERROR$/* * Copyright (c) 2019 ANSYS medini Technologies AG * All rights reserved. */load(".lib/diagram.js");// search for events that are visible on diagramsvar visibleEventsNodes = finder.findByType(Metamodel.FTA.EventNode).filter(function (event) { var result = {}; var color = undefined; var onAnyDia = onAnyDiagramInScope(finder.scope, event, result); if (onAnyDia) { // colour can be obtained in the result object (the shape) color = result["shape"].fillColor; console.log("Event {0} is on diagram with color => {1}", event.id, color); } // TODO Compare color code return onAnyDia && (color == 10265827);}).asArray();// TODO Do something with the nodesalert("There are " + visibleEventsNodes.length + " nodes with color XXX");
Just play a bit and find the color code you are using (its a number).
Happy Scripting
Jan
glad to have you here in the forum. Well, counting objects is relative easy, for example like this one-liner:
alert("Number of events Events: " + finder.findByType(Metamodel.FTA.Event).size());
However, I am not sure what you mean with "with ASIL", FTA events do not have an ASIL in medini.
Could you elaborate a bit on that?
Hello,
Thanks for your quick reponse, you are true ASIL is not from medini, it is a Custom profiling attribute. Now i want to get No.of events (with ASIL >QM) in the swFTA. Could you please help me on this?
I wanted to get the events markedas red color background. Is there any possibility for this?
Well, you need to enhance the script and reduce the finder to events that match a certain filter. See the scripting guide how to write a filter function.
Would look like:
function withASIL(event) { return event.asil = "A" || event.asil = "B"; // etc etc}alert("Number of events Events: " + finder.findByType(Metamodel.FTA.Event).filter(withASIL).size())
Coloring in diagrams is possible, I think we had a similar request. Have you searched the forum for that already?
Regards Jan
Thanks again for response.Regrading coloring i could not find the post.Could you please share me the link/solution if possible?
Hello Jan,
I have gone through the coloring in diagrams example, but i do not understand how to filter events with red color background.Could you please help me?
Where have you found it actually, could you pinpoint me?
https://medini.freshdesk.com/support/discussions/topics/1000087898
Ah, I thought you want to color them, not to filter based on their color.
That's of course bit more tricky because:
Following are the clarifications from my side.
OK, got it. I'll try to prepare a skeleton that you can test and continue.
Thanks for providing me the solution.It solved my requirement.
I have performance problem with the below solution it is taking more than 30 seconds, results getting 'Scripts execution was stopped by engine or runtime' while integrating with BIRT report.
Is there any possibility to improve the performance.
function identifyUndecidedEvents(){
visibleUndecidedEvents = myPrjFinder.findByType(Metamodel.FTA.EventNode).filter(function (event) {
var result = {};
var color = undefined;
var onAnyDia = onAnyDiagramInScope(finder.scope, event, result);
if (onAnyDia) {
color = result["shape"].fillColor;
// console.log("Event id {0} name {1} is on diagram with color => {2}", event.id,event.name, color);
}
return onAnyDia && (color == 10265827);
}).asArray();
countRationaleForUndevelopedEvents();
return [visibleUndecidedEvents.length,undecidedEventsIdsRationale.toString(),undecidedEventsIdsRationale.length,undecidedEventsIdsNoRationale.toString(),undecidedEventsIdsNoRationale.length];
/***
* Script file for returning the Diagram based on the back ground color
* @author Gangadhar Kotagiri
*/
/**
* Returns <code>true</code> if the given element is visible on the given
* diagram, <code>false</code>otherwise. Note that this function work for
* elements that are represented as shape but also as connector.
*
* @param {PJDiagram}
* diagramHook
* @param {Object}
* element
* result
function onDiagram(diagramHook, element, result) {
var diagram = diagramHook.diagram;
// diagrams are not in the containment hierarchy
var diagramFinder = Global.getFinder(diagram);
var shapes = diagramFinder.findByType(Metamodel.notation.Shape, false).and("element", element);
if (!shapes.isEmpty()) {
result["shape"] = shapes.first();
return true;
return false;
* Returns <code>true</code> if the given element is visible on any of the
* given diagrams, <code>false</code>otherwise. Note that this function work
* for elements that are represented as shape but also as connector.
* @param {Array}
* diagrams
* @see #onDiagram
function onAnyDiagram(diagrams, element, result) {
for (var i = 0; i < diagrams.length; i++) {
var dia = diagrams[i];
if (onDiagram(dia, element, result)) {
// bail out as early as possible
* Returns <code>true</code> if the given element is visible on any diagram in
* the given scope, <code>false</code>otherwise. Note that this function work
function onAnyDiagramInScope(scope, element, result) {
// the scope might be a model - jump to the proxy to catch diagrams
var container = scope.mediniGetContainer();
if (!container && !scope.mediniGetOpposites("originalModel").isEmpty()) {
var proxy = scope.mediniGetOpposites("originalModel").get(0);
scope = proxy;
var diaFinder = Global.getFinder(scope);
var diagrams = diaFinder.findByType(Metamodel.projectmodel.PJDiagram).asArray();
return onAnyDiagram(diagrams, element, result);
maybe onAnyDiagram is not optimal wrt performance. Anyhow, what is "countRationaleForUndevelopedEvents" actually doing?
Btw. we updated the diagram.js library and introduced some caching.
See https://medini.freshdesk.com/a/solutions/articles/1000273630-scripting-libraries and https://medini.freshdesk.com/support/discussions/topics/1000092399