Connecting to External Code

Connecting to External Code

che_wei_c
Not applicable
61 Views
4 Replies
Message 1 of 5

Connecting to External Code

che_wei_c
Not applicable

[ FlexSim 22.2.0 ]

Hi,

I've tried to practice this example to connect external python code by the following line:

https://answers.flexsim.com/questions/110833/future-python-and-flexsim-integration.html

However, it seemed to have a bug here.

Could you help to clarify it?

Thanks

Wade


1679783649795.png

TestFlexsimPy.py

Pull_from_Queue.fsm

0 Likes
Accepted solutions (1)
62 Views
4 Replies
Replies (4)
Message 2 of 5

moehlmann_fe
Explorer
Explorer
Accepted solution

You defined the code to call python in a user command but in the Pull Strategy code you call a label "CallPython" that does not exist on the processor instead. Either actually use the user command or move the code to call python to the label.

Your python code won't work because:

- you don't pass the jobs array to python when you call "evaluate()".

- options is not defined anywhere in the python code

- you didn't add fields that contain the queue name and item rank to the list, so the entries of the jobs array only contain four elements, not six like the python code assumes in the return value

Also be aware that the Pull Strategy code will not refire automatically. It executes on reset (which will not return a valid item since the queues are all still empty) and when an item leaves the processor. To "kickstart" the processor you will have to execute the code manully when items become available (by evaluating the node the code is defined on in the variables attributes of the processor.

1679903992333.png

0 Likes
Message 3 of 5

che_wei_c
Not applicable

Hi Felix,

Thanks for your comments. However, I still have some questions that I can't understand that address below:

1. How do I call python (CallPython) to the label?

2. Is "you don't pass the jobs array to python when you call "evaluate()"." sloved by call python code?

3. I can't understand what's meaning of "options is not defined anywhere in the python code"

4. I try to define "queuename" and "itemrank" in the list, however, I don't this definition, could you help provide the definition?

5. How to set this, "To "kickstart" the processor you will have to execute the code manully when items become available" ?

Thanks for your patiention.

Wade

0 Likes
Message 4 of 5

moehlmann_fe
Explorer
Explorer

1. You add a FlexScript type label and add the same expression to it as in the user command.

2. You pass in the jobs array as a parameter into the evaluate command (...evaluate(jobs))

3. In the python code you wrote "random.choice(options)" without options being declared in the code prior to that.

4. queuename: "value.up.name" (value -> item, value.up -> queue)
rank: "value.rank"

5. Get a reference to the node and call evaluate on it to execute the Pull Strategy again.

pull-from-queue_fm.fsm

testflexsimpy.py

0 Likes
Message 5 of 5

che_wei_c
Not applicable
Hi Felix,

Thanks for your great support always.

Wade

0 Likes