Hi,
Some people asked how to automatically assign IDs to functions, which do not yet have IDs defined - e.g. for new functions after an updated import from tools like Rhapsody.
Here is an example snipped, with a full script file attached.
Note: Make sure the autocounter is set right upfront (especially with medini <2021 R2.1 or with de-activated option "Prevent duplicated IDs") in order to avoid duplicated IDs.
// find all functions
var functions = finder.findByType(Metamodel.sysml.SysMLActivity).asArray();
functions.forEach( function assignMissingID (func) {
// only assign new ID, if current one is empty
if (!func.id) {
// "id" is the name of the attribute to set (and also the to look for current counter), "F001" is a fallback value.
func.id = AutoCounterSupport.createUniqueIDString(func, "id", "F001");
console.log("Assigned new ID {0} to function {1}",func.id, func.label);
} else {
console.log("No need to update function {0}",func.label);
}
});
Happy scripting!
Nils