Create MTBF MTTR using flexscript

Create MTBF MTTR using flexscript

mustafa_l
Not applicable
16 Views
8 Replies
Message 1 of 9

Create MTBF MTTR using flexscript

mustafa_l
Not applicable

[ FlexSim 18.1.2 ]

How do I create a MTBF object via flexscript?

0 Likes
Accepted solutions (1)
17 Views
8 Replies
Replies (8)
Message 2 of 9

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

To add a new MTBF object to the toolbox you can use this line of FlexScript

treenode table = applicationcommand("addmtbfmttr");

If you want to configure the tool at all it gets a little more tricky. We don't currently have a nice API for configuring the MTBF, although we are hoping to add one down the road. You can still do everything through FlexScript, but nothings documented or very discoverable at the moment.

If you want to add new members to the tool you would use code like this:

treenode obj = model().find("Processor1");
treenode members = getvarnode(table, "members");
treenode timetables = getvarnode(obj,"timetables");

createcoupling(members, timetables);
members.last.name = obj.name;
timetables.last.name = table.name;

If there are any other things you want to configure through code we can help you find the needed code.



Matthew Gillespie
FlexSim Software Developer

Message 3 of 9

mustafa_l
Not applicable

Thanks,

A follow up question :

treenode table = applicationcommand("addmtbfmttr");

opens up the pop up window. How do I close it using flex script?

0 Likes
Message 4 of 9

Matthew_Gillespie
Autodesk
Autodesk

Add a 1 as a second parameter if you don't want the properties window to open:

applicationcommand("addmtbfmttr", 1)


Matthew Gillespie
FlexSim Software Developer

Message 5 of 9

mustafa_l
Not applicable

The code to add the coupling gives me an error on the last two lines

exception: FlexScript exception: Property "last" accessed on invalid node. at MODEL:/Tools/UserCommands/addBreakDowns/code

exception: FlexScript exception: Property "last" accessed on invalid node. at MODEL:/Tools/UserCommands/addBreakDowns/code

exception: FlexScript exception: Property "last" accessed on invalid node. at MODEL:/Tools/UserCommands/addBreakDowns/code

exception: FlexScript exception: Property "name" accessed on invalid node. at MODEL:/Tools/UserCommands/addBreakDowns/code

how do I resolve this?

0 Likes
Message 6 of 9

Matthew_Gillespie
Autodesk
Autodesk

Can you post the code you're using? And do you have an object called Processor1 in the model? That line should be changed to the object you actually want to add.



Matthew Gillespie
FlexSim Software Developer

Message 7 of 9

mustafa_l
Not applicable

Here is my code:

basically, I changed a few variable names and changed the "Processor1" string that you mentioned earlier @Matthew Gillespie

breakdown = applicationcommand("addmtbfmttr",1);

treenode mtbf = getvarnode(breakdown, "mtbf");

treenode mttr = getvarnode(breakdown, "mttr");

treenode firstmtbf = getvarnode(breakdown, "firstmtbf");

treenode proc = model().find(gettablestr(procInfoTable,i,col_proc_name));

treenode members = getvarnode(breakdown, "members");

treenode timetables = getvarnode(proc,"timetables");

createcoupling(members, timetables);

members.last.name = proc.name;

timetables.last.name = breakdown.name;

0 Likes
Message 8 of 9

mustafa_l
Not applicable

Edit: I did a bit of debugging and found that the 1 in, applicationcommand("addmtbfmttr", 1)

was causing the error. (obviously withoutthe 1 the application just opensup a bunch of unwanted mttr windows.

0 Likes
Message 9 of 9

Matthew_Gillespie
Autodesk
Autodesk

Huh, it no longer returns the created node if you pass in the 1. That looks like a bug.

Here are two workarounds:

applicationcommand("addmtbfmttr", 1);
treenode table = model().find("MTBFMTTR").last;

OR

treenode mtbfmttr = applicationcommand("addtool", "MTBFMTTR", library().find("MTBFMTTR"));


Matthew Gillespie
FlexSim Software Developer

0 Likes