question

Swami Premnidhi avatar image
0 Likes"
Swami Premnidhi asked Swami Premnidhi commented

Add Objects To Statistics Collector Using Code

Hi Support,

I want to add objects dynamically to enumerate event on reset in the statistics collector.

Attaching a model for your reference.

Similar to the link given below. May be a function_s() code will do the job. But don't know the exact string to be used in the function.

https://answers.flexsim.com/questions/43999/dynamically-adding-events-to-statistics-collector.html

Thanks in advance.

Regards,

Swami

FlexSim 20.2.2
flexsim 20.2.2statistic collectordashboard display
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi @swami P2, was Jordan Johnson's or jason.lightfoot's answer helpful? If so, please click the red "Accept" button on one of their answers. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Swami Premnidhi commented

You can add a Group to the list of objects to enumerate. So I would put the object in a Group, and then add that Group to the list of objects to enumerate, instead of enumerating the object directly. Whatever is in the Group on reset will be added to the chart.


· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Swami Premnidhi avatar image Swami Premnidhi commented ·

Hi @Jordan Johnson Thanks for reply.

In the main model I am changing the number of operators using global table for different scenario thatswhy I added operator dynamically to statistic collector to get distance travelled statistics using code. (Do not want to add group or operator manually)

problem is I am not getting any data in view table of statistic collector.

Sample model Sample Model for enumerate.fsm

Thanks.

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Swami Premnidhi commented ·

You only have to create the group once. You won't have to do it every scenario. If you copy an object that is in a group, then the copy is also in the group, automatically.

If you are making operators during the model run, rather than at reset, then you should not use an enumerate event. Rather, you should listen to the event that creates the operators, and use that event to add the operators to the table.

Unfortunately, I can't download your attachment. Can you try re-uploading it?

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Jordan Johnson ♦♦ commented ·

Here is an example model that makes as many operators as you put in the global table value. All of them are added to the group. To use, change the value in the table, and then reset the model. You'll see that however many operators there are, they are added to the table.

AutoAddToTable.fsm

0 Likes 0 ·
autoaddtotable.fsm (36.4 KiB)
Swami Premnidhi avatar image Swami Premnidhi commented ·

@Jordan Johnson Thanks for your support. It's working.

0 Likes 0 ·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jordan Johnson commented

As Jordan states in your link - this may change in the future but for now you can try this:

Object X = Model.find("TrolleyOutLoc");
treenode enumerator = model().find("Tools/StatisticsCollectors/StatisticsCollector1>variables/eventReferences/Enumerate1");
function_s(enumerator, "addObject", X);


· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Swami Premnidhi avatar image Swami Premnidhi commented ·

Hii @Jordan Johnson @jason.lightfoot Thanks for your response.

Sorry for delayed response.

As per your suggestion I updated now object(i.e.operator) is added to enumerate in statistics collector.

But It is not updating view table in statistic collector.

I am trying to generate distance travelled statistics for operator.

Attaching the model and screenshot for your reference.

In the sample model I worte code on message trigger of queue3 for creating operator and adding to enumerator. and also on reset for deleting the same.

Thanks in advance.


Sample Model for enumerate.fsm

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Swami Premnidhi commented ·

If you enumerate the group like this:

Then you can add/remove members from that group on reset. Whatever is in that group will be in the table. You can do that by using the green plus button in the Objects area, and choose Add Group.

0 Likes 0 ·
1602527121710.png (47.0 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.