question

Sebastien avatar image
0 Likes"
Sebastien asked Sebastien commented

Change Group members with code during simulation

Hello,
I am trying to change the members of a location group with code but during a simulation run. With our first tests, it seems that the group content is updated on reset, also when wu use group.addmember()

Is it possible to change the location members of a group during a simulation run ? If yes, how ?

FlexSim 20.2.3
model rungroupmember
5 |100000

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

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Sebastien commented
Group("Locations").addMember(myobject) 

works but you also need to push to the Locations global List:

List("Locations").push(myobject);
· 5
5 |100000

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

Sebastien avatar image Sebastien commented ·

Thank you @Jason Lightfoot for your answer.

Actually I made a mistake when I defined myobject. I used Object instead of treenode.

Then with treenode definition it worked but it did not work when I tried pushing to the list. Maybe because the object was already in another group and hence already in the Locations global List ?

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Sebastien commented ·
It shouldn't make a difference whether you put an object variable or treenode to the list - if the list has unique values checked it will only have one list entry, even if you push it twice.
0 Likes 0 ·
Sebastien avatar image Sebastien commented ·

Hi again @Jason Lightfoot ,

I am working with multilocations dynamicaly added or removed with flexscript. Sometimes I have strange behaviors and although I do as you told me I was wondering if you could explain why the entries have to be changed in both the Group("groupName") and the global List("Locations") ? Maybe this is different with Multilocations ?

I use Group.removemember() and List.pull() / Group.addmember() and List.push().

Attached you can find an example where I could not make it work. After 50s chairs one should be removed from the group. After 100s they should be back and available for seating.

2023_05_02_Test_Chairs_Acquire.fsm


0 Likes 0 ·
Jeanette F avatar image Jeanette F ♦♦ Sebastien commented ·

Hello @Sebastien,

Would it work to use a time table to add or remove members?

I added the sublocations (individual chairs) of the multilocation chairs 1 to the time table. This can be done when you select the multilocation and in the properties panel under the Multilocation tab select the Edit Mode. This will allow you to select the individual members of the group.

1683165858882.png

I then set a label on each chair called available and set it to 1. This label will be used in the location list to decide if a patient can pull it or not, so it needs to be added to the list and resource filter.

1683166143847.png

1683166080847.png

2023-05-02-test-chairs-acquire_2.fsm



1 Like 1 ·
Sebastien avatar image Sebastien Jeanette F ♦♦ commented ·
Thank you @Jeanette F for your answer.


It helped me to figure out why I had my issue. I was actually not taking the sublocations into account when I was pulling or pushing them to the list.

Sor for anyone looking for an answer for multilocations the code should look like this:


Group("Locations").addMember(multilocation);

for(int i=1; i<= subLocations.length; i++){
    List("Locations").push(subLocations[i]);
}


Best regards,
1 Like 1 ·