question

Nip J avatar image
0 Likes"
Nip J asked Nip J edited

how to access sub treenode with Model.find()

Dear Community,

In the uploaded test file, I would like to call every patient´s name when one arrives at a kiosk, using Model.find() with the kiosk´s trigger “on entry”. From what I can see is, that the function Model.find(“patientname”) is only able to access the patients´ names, which – in the model tree – are in the same hierarchy- level as “Tools”(picture1&2). That means, if a patient is moving outside of a location / waiting line / … the name is accessible via Model.find(). But on the other hand for example, if a patient is standing in a waiting line, its tree object is not listed directly underneath “Tools”, but within the waiting line´s node: so in this case the hierarchy- level is not the same as “Tools” and results in a <no path> output in the output console.

Question: how is it possible to access a patient´s name, no matter where he / she is, especially in a more complex environment with several locations where the patient constantly switches from one location to another?

I appreciate any ideas. Best regards, NJ

FlexSim 20.1.2
flexsim 20.1.2model treemodel.find
picture1.png (59.1 KiB)
picture2.png (132.9 KiB)
testfile.fsm (52.1 KiB)
· 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 @Nip J, was Matthew Gillespie's answer helpful? If so, please click the red "Accept" button on their answer. 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 ·

1 Answer

Matthew Gillespie avatar image
2 Likes"
Matthew Gillespie answered Nip J edited

The Model.find() method takes a path to the object. This is why when guest2 is in WaitingLine1, Model.find("guest2") doesn't work, but Model.find("WaitingLine1/guest2") does. There is a way to have the find() method look recursively through all layers of the model by putting a ? at the start of the path:

Model.find("?guest2")

However, I don't recommend this because it's quite slow.

I would recommend using pointers to the patients so you always know exactly where they are. One way to do this is to push patients on a list when the arrive and pull them off the list when they leave. Then you can print all the patients on the list at any time. I did this in the attached model. I made a global list called Patients.

First I push the patients on the list when they arrive:

List("Patients").push(patient);

Then when they leave I pull them off:

List("Patients").pull(patient);

Then I made a user command called printPatients() that prints all the patients on the list:

Array patients = List("Patients").entries().toArray();

for (int i = 1; i <= patients.length; i++) {
    print("Guest " + string.fromNum(i) + ": ", patients[i].value);
}

Then I call that user command from the Kiosk's OnEntry trigger.

testfile_1.fsm


testfile-1.fsm (52.2 KiB)
· 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.

Nip J avatar image Nip J commented ·

Good day @Matthew Gillespie and @Ben Wilson,

sorry for the late respond.

Thanks for the quick answer and the very detailed explanation: it really helped me out and brings me closer to what I want. I haven´t respond, yet, since I am now thinking about how to use your instruction to achieve the next steps. Thanks again for your help.

0 Likes 0 ·