Below you can find a solution how user defined project variables can be used i.e. for the update of user variables in HW part libraries or BOM.
The implementation of IEC61709 in medini analyze is missing some factors according to the complex mission profiles described in the IEC. In order to avoid a manual update of these factors for all HW parts I planned to do this automatically. Because these factors may differ from project to project we added user defined variables to the profile for the project.

The idea was to calculate i.e. the variable pi_OP by a script in the profile itself and to copy the result to each HW part for the failure rate calculation based on IEC61709 by using the scaling.

Unfortunately, currently these user defined project variables can not be used directly to update a variable used for failure rate calculation.
The solution was to store the variable in a CSV-file (already described in another topic by Jan) and to read the variable to use it to update each pi_OP instance in the HW part library.
1st step: Store variable in CSV file
/*
* v2020-03-19 - initial version
*
* This script exemplary extracts information from a selected project
* and exports it as "comma separated list" (CSV) to the Workspace.
*/
var text = ""; //headline; // text to export
/*
* Handle each element. You may extract arbitrary attributes (element is of type
* SysMLElement)
*/
function handleElement(element) {
text += element.pi_OP;
}
/*
* Main function doing the "main" job.
*/
function main() {
handleElement(finder.project);
writeToFile(text, __filedir+"/pi_OP.csv"); //same directory than location of script
var piVar = text;
console.log("Value of pi_OP in project: " + piVar);
return "Project data was extracted and put into " + __filedir + "/pi_OP.csv";
}
/*
* Helper to store the text into a file using the *default* character encoding.
*/
function writeToFile(text, fileName) {
var file = new java.io.File(fileName);
var writer = new java.io.FileWriter(file);
writer.write(text);
writer.close();
}
// do it!
main();
The variable pi_OP defined in profiling project is stored in "pi_OP.csv"
2nd step: Read CSV file and update all pi_OP in HW part library
// $EXPERIMENTAL$ $STRICT_MODE$ $WARNING_AS_ERROR$ $ENHANCED_CONTAINMENT_ACCESS$
// $DEBUG$ <- move to first line to enable debugging
/*
* Usage:
* - Apply on Hardware Part Library (Element Library containing element types (part definitions))
* - Apply on BOM (System Model containting parts (elements))
*
* Task of the script:
* update variable pi_OP in HW part library with value read from csv file
*/
load("../.lib/factory.js"); // required to create variables
var verbose = true; // {true; false}
var piOP;
//DONT CHANGE ANYTHING BELOW THIS LINE
function checkIfVarExists(vars, name) {
var arr = vars.toArray();
for (var i = 0; i < arr.length; i++) {
if (arr[i].name == name) {
return true;
}
}
return false;
}
function returnVarIfExists(vars, name) {
var arr = vars.toArray();
for (var i = 0; i < arr.length; i++) {
if (arr[i].name == name) {
return arr[i];
}
}
return false;
}
function findOrCreateVariable(scope, name) {
var varIfExists; // {false; searchedForVariable}
var bVerbose = false; // {true; false}
// check if variable exists in "variables"
varIfExists = returnVarIfExists(scope.failureRateData.variables, name);
// if it exists, then return it
if (varIfExists instanceof FailureRateCatalogsPackage.Literals.FR_VARIABLE) {
if (bVerbose) console.log("variable {0} found in 'variables'", name);
return varIfExists;
}
// if it does not exist, then check if variable exists in "userVariables"
varIfExists = returnVarIfExists(scope.failureRateData.userVariables, name);
// if it exists, then return it
if (varIfExists instanceof FailureRateCatalogsPackage.Literals.FR_VARIABLE) {
if (bVerbose) console.log("variable {0} found in 'userVariables'", name);
return varIfExists;
}
}
function modifyElement(element) {
if (verbose) console.log("scope: " + element.name);
// only handle elements that may carry failure rate data: element types (SysMLBlock) and elements (SysMLPart)
if (!Metamodel.safetyModel.Failable.isInstance(element)) {
return;
}
// only handle elements that have failure rate data
if (!element.failureRateData) {
return;
}
// Hardware Part Library/System Model: add/modify variable
var sVar;
var vVar;
var varIfExists;
// variable pi_OP (factor used for mission profiles)
sVar = "pi_OP";
vVar = findOrCreateVariable(element, sVar);
varIfExists = returnVarIfExists(element.failureRateData.userVariables, sVar);
// if it exists, then return it
if (varIfExists instanceof FailureRateCatalogsPackage.Literals.FR_VARIABLE) {
if (true) console.log("variable {0} found in 'variables'", sVar);
vVar.value = piOP; //update pi_OP by new value
}
}
function readFromFile(fileName) {
var file = new java.io.File(fileName);
var text;
var A;
var piVar;
var reader = new java.io.FileReader(file);
piVar="";
A = reader.read();
text = String.fromCharCode(A);
piVar = piVar + text;
while(A != -1) {
A = reader.read();
text = String.fromCharCode(A);
piVar = piVar + text;
}
piOP = parseFloat(piVar); //convert piVar as string to piOP as number
console.log("pi_OP read from CSV: " + piOP);
reader.close();
}
function main() {
readFromFile(__filedir+"/pi_OP.csv");
// make sure something is selected
if (selection) {
// by default we scan selected elements
var scan = selection;
// however, is a SINGLE package is selected, we scan the tree below
if (selection.length == 1 && selection[0].prototype == Metamodel.sysml.SysMLContainerPackage) {
scan = Global.getFinder(selection[0]).findByType(Metamodel.safetyModel.Failable).asArray();
}
if (verbose) console.log("selection is a {0}", selection[0].prototype.name);
scan.forEach(modifyElement);
} else {
console.log("Please select one or more elements or a single package to reset variables to derived.");
}
console.log("pi_OP updated to: "+piOP);
console.log("finished\n\n");
}
main();
Example:
pi-OP in project:

Select the project in "Model Browser" and run script to store the variable in CSV-file.
pi_OP stored in CSV file:

Select HW part library of your project in "Model Browser" and run second script
The variable pi_OP should be than updated for each HW part.
