Change Group members with code during simulation

Change Group members with code during simulation

sebastien_b49
Advocate Advocate
267 Views
6 Replies
Message 1 of 7

Change Group members with code during simulation

sebastien_b49
Advocate
Advocate

[ FlexSim 20.2.3 ]

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 ?

0 Likes
Accepted solutions (1)
268 Views
6 Replies
Replies (6)
Message 2 of 7

jason_lightfoot_adsk
Autodesk
Autodesk
Accepted solution
Group("Locations").addMember(myobject) 

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

List("Locations").push(myobject);
Message 3 of 7

sebastien_b49
Advocate
Advocate

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
Message 4 of 7

jason_lightfoot_adsk
Autodesk
Autodesk
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
Message 5 of 7

sebastien_b49
Advocate
Advocate

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
Message 6 of 7

Jeanette_Fullmer
Community Manager
Community Manager

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



Message 7 of 7

sebastien_b49
Advocate
Advocate
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);
}


Best regards,