As you know, we are working on an extension of the Scripting API that allows users to create objects, i.e. an Object Factory. To drive this process we decided to start with a script library that offers a simple factory API for a bunch of selected object types as Failure Modes or Requirements. That famous factory.js library is now used in quite a few scripts and the number of supported object types is growing with each version. Still, the API is not settled and a final feedback round is pending. But that's a different story.
New: Safety Mechanisms
In this thread I would like to announce a new version of the factory library that can create Measure Catalogs as well as Safety Mechanism Catalogs and their respective content. Some care has to be taken when creating the collections since their collection type has to be set afterwards. An example of a Measure Catalog with Measures:
// create a measure catalog with measures
var catalog = Factory.createElement(finder.getScope(), Metamodel.safetyModel.MeasureCatalog);
catalog.name = "My Measures";
var m1 = Factory.createElement(catalog, Metamodel.safetyModel.Measure);
m1.name ="Prevent anything";
var m2 = Factory.createElement(catalog, Metamodel.safetyModel.Measure);
m2.name ="Observe the rest";
As you can see, the create catalog can be used right away to fill it with Measure instances. Its different if you create catalogs for Safety Mechanisms:
var catalog2 = Factory.createElement(finder.getScope(), Metamodel.safetyModel.MeasureCatalog);
catalog2.name = "My Mechanisms";
catalog2.collectionType = Metamodel.safetyModel.SafetyMechanism;
var sm1 = Factory.createElement(catalog2, Metamodel.safetyModel.SafetyMechanism);
sm1.name ="Null Check";
var sm2 = Factory.createElement(catalog2, Metamodel.safetyModel.SafetyMechanism);
sm2.name ="CRC";
Its important to set the collection type to Safety Mechanism, otherwise any creation of new mechanisms will fail with an exception. Last but now least an example of an Error Collection for completeness (this was possible with earlier versions too:
// create a failure collection with failure modes
var collection = Factory.createElement(finder.getScope(), Metamodel.safetyModel.FailureCollection);
collection.collectionType = Metamodel.safetyModel.FailureMode;
var e1 = Factory.createElement(collection, Metamodel.safetyModel.FailureMode);
e1.name ="Short";
The latest factory is attached to this post. Happy Scripting!