Dear Jan, dear community,
did somebody already use a script to craete a child diagram? I was unable to find a matching function in neither "factory.js" nor "diagram.js".
Any hints? (I'm using v2019R1.1)
Thank you and best regards
Peter
There is "__createFTAModel()" available in the factory.js that I did not spot before. Let me check this out...
hm no, I already have a FTA model. I require the equivalent binding that corresponds to the diagram and not the model:
var CreateFTAModelOperation = bind("de.ikv.analyze.core", "de.ikv.analyze.core.operations.CreateFTAModelOperation", false);
Is there a (hacky) way existing, how one could peek into the (undocumented) core operations of medini analyze? :-)
Jan, you won't be happy :-D
Best regards
hmmm.... :-)
Jan, is this the right track? (If this works -- I have to still test it -- could this be eventually introduced to factory.js).
var CreateNewFTADiagramOperation = bind("de.ikv.analyze.core", "de.ikv.analyze.core.operations.AbstractNewPJProxyModelOperation", false);function __createFTADiagram(scope) { if (!scope) { console.error("Scope is undefined in create method!"); } // create one // public AbstractNewPJProxyModelOperation(String name, PJScope scope, String label) var op = new CreateNewFTADiagramOperation("", scope, ""); // projectmodel.PJDiagram (modelID = "FaultTreeAnalysis" op.execute(null, null); return op.getNewModel();}
at least I know that this does not work...
example: I call the script while either a FTA model or a FTA diagram is selected, it fails with
error instantiating (TypeError: Expected argument of type object, but instead had type string): class de.ikv.analyze.core.operations.AbstractNewPJProxyModelOperation is interface or abstract
with the script's main content being
var scan = selection; // by default we scan selected elements var source = selection[0]; console.log("source: ''{0}''", source.name); var myDiagram = __createFTADiagram(source); myDiagram.name = "test"; console.log("done"); return;
Have a nice weekend!
ah well, I'll try to learn how to implement my own class extending that abstract class, just like the class CreateFTAModelOperation does it, but I'm really not sure, if this is possible from inside medini :-/
This is really considerably out of my comfort zone :-D
Jan? :-) :-)
Hi Peter,
seems that you had a good time on Friday, haha.
Actually I did not find anything ready yet to create diagrams - hence its missing in the factory.
Seems that you are the first one.
I am indeed not that happy if you try to use internal classes yourself. I have access to he code base and can disclose parts of it using the library approach but without ... well, it eats time.
I will try to enhance the factory to create Diagrams, though its a bit tricky.even in the native code.
Not sure I can disclose the right operation.
Happy Scripting
Jan
PS. Any chance to upgrade to 20.1 or at least 19.5?
Dear Jan,
I understand that my request is on the edge, so I did not detail any further as to how I determined the callee candidate.
Well, currently we try to delay on unneccessary version migrations, due to severe compatiblity implications. As many clients need to be migrated (currently manually) this would mean a significant overhead, which we avoid as long as we can. Currently, newer versions don't offer specific advantages to us (yet!).
If you provide a solution that strictly requires a newer version, this would change balances somewhat.
In any case I appreciate you looking into this.
No problem, that area hasn't changed since many version, should be compatible for any 19,.x and 20.x version.
May take a few days though.
Peter,
is it really about child diagrams or plain diagrams at root level?
Later one seems to be easier to achieve.
child diagrams is preferable, but I'm also interested in the plain diagram creation below the FTA model (root). I just tested and confirmed that nesting can then by obtained using drag&drop.
OK. I have a working solution, though it requires another tweak in the calling script.
I will post an intermediate update here which you may try as "beta tester".
Sounds okay?
Sure :-)
Hello Peter,
attached you can find an intermediate version of the factory. With that you should be able to create diagrams within top level models. Code may look like:
// create a diagram in a system modelvar dia1 = Factory.createElement(scope, Metamodel.projectmodel.PJDiagram);dia1.name = "My first system diagram";
At the moment, scope can be a System, Requirements or FTA model.
Please try and post any feedback here.
If I use factory to create a FTA model, it also generates a PJDiagram and TLE. How do I access the top level event that was created? For example, when you manually create a new FTA model it prompts you to pick the name of the TLE also. Would like to achieve this (grab TLE and rename it) through javascript.
I think that should be "rootNodes", so
var fta = Factory.createElement(.....)var tle = fta.rootNodes.get(0);
Hi Jan, is there a way to access the child diagrams as an object of the model after they have been created?
Hi Tom,
I think there is no such easy to use function at the moment,. Main reason is that diagrams only indirectly belong to a model: they are hooked in the same proxy object that is used to hook the model into the overall project.
The diagram.js library could offer such a function though, so in case you really need it we could expose it in that library, its already partially in there but not exposed.
Regards
/** * Returns all shapes in the given diagram or - if element is defined - only * those for the given element. * * @param {PJDiagram} * diagramHook * @param {Object} * element */function getShapes(diagramHook, element) { var diagram = diagramHook.diagram; // diagrams are not in the containment hierarchy var diagramFinder = Global.getFinder(diagram); var shapes = diagramFinder.findByType(Metamodel.notation.Shape, false).filter(function (shape) { return (element == undefined) || (element == shape.element); }); return shapes.asArray();}
I found this in the Diagram.js
If I'm understanding this right it looks like diagramHook is what allows users to reference diagrams, but I'm still not sure how to define the scope to be a specific FTA model. If it's possible would you be able to expose that part of the script? I am currently trying to automate the generation of multiple diagrams and this would be super helpful with regards to being able to organize and keep track of them during execution and development.
we extended the diagram.js library a bit and added a new function
getAllDiagrams(scope)
That should return you all diagram proxies for a given model or sub-diagrams for a given diagram proxy. Maybe you can give that a try. See the test script how to use it.