question

Nick avatar image
0 Likes"
Nick asked Logan Gold commented

FlexSimPy - Running TestSendReceive.fsm Independently from Python

With some assistance from a coworker, I was able to build and run FlexSimPy using the example provided in the install package. Specifically, I successfully ran `TestFlexSimPy.py` and communicated with the unopened `TestSendReceive.fsm`, allowing the value to pass back and forth between them.

However, when I opened the `TestSendReceive.fsm` file and attempted to run it independently, I encountered a console error:1728416998551.pngFrom past experience, I suspect that FlexSim is trying to locate the Python module FlexSimPy but cannot find it.


In my troubleshooting, I attempted to create a "symbolic reference" for the FlexSimPy Python module. I modified the code from:

external python "FlexSimPy" "sendToController";

to:

external python "FlexSimLibs.FlexSimPy" "sendToController";

with `FlexSimLibs.FlexSimPy` externally referenced in an effort to resolve the issue. Unfortunately, this change didn’t fix the error, and it also caused the `TestFlexSimPy.py` script to stop working.

After discussing this with my colleague, we arrived at the possibility that .fsm models designed with this type of connectivity might not be intended to run independently of a Python script that creates and calls the .fsm file.

Am I missing something here? Is my .fsm FlexSim file not set up correctly, or is my coworker’s assumption correct?

FlexSim 24.2.1
pythoninteraction between flexsim and pythonflexsim pythonpython connection with flexsim
1728416998551.png (63.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.

Logan Gold avatar image Logan Gold ♦♦ commented ·

Hi @Nick, was Kavika F's answer helpful? If so, please click the "Accept" button at the bottom of 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 comment back to reopen your question.

0 Likes 0 ·

1 Answer

Kavika F avatar image
0 Likes"
Kavika F answered

Hey @Nick, from the error that you're getting in the system console, it seems that the FlexSim.pyd isn't in the same directory as the model.

"FlexSimPy" is the name of the file (without extensions) that contains the python code. When going through the setup described in the README of the FlexSimPy github repo, steps 3-5 mention building the FlexSimPy.sln in visual studio. Make sure that you have the right python version selected before building the solution.

That building process outputs files in FlexSimPy/out/<python_version>/. One of those files is called "FlexSimPy.pyd". This file is needed for you to get the python script working as well as the FlexSim model since they both reference this file. You can copy the file from the output folder and put it in the same folder as your model to get things working.

1729526282715.png


If you experience other exceptions during the process, ensure that you're using the same python version as your command prompt says you have downloaded. For example, if you have Python 3.11, ensure that (1) you build the VS solution with Rel_3_11,

1729526160633.png

(2) your FlexSim Global Preferences > Code tab has Python 3.11 selected,

1729526106500.png

and (3) if you're running the python script in Visual Studio Code, you have the right python version selected in the bottom-right corner.

1729526217366.png


1729526106500.png (21.7 KiB)
1729526149067.png (23.5 KiB)
1729526160633.png (23.5 KiB)
1729526217366.png (14.6 KiB)
1729526282715.png (14.5 KiB)
5 |100000

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