question

Mischa Spelt avatar image
0 Likes"
Mischa Spelt asked Mischa Spelt commented

Cannot bind to Python function

The ability to connect FlexSim and Python looks really cool so I decided to make a simple test case. Rather than controlling FlexSim from Python I first decided to see if I can call a function from FlexSim.

I created a Test.fsm model and put a simple Python script in FlexSimPy\FlexSimPy.py. But when I try to call the Python function I get

  1. exception: Code Binding Error: could not bind to function
  2. Node: /Tools/UserCommands/Add/code
  3. Binding string: external python "FlexSimPy/FlexSimPy" "add"
  4. Windows Error Code : 126

As far as I can see code 126 means missing DLL, but according to the GitHub documentation,

The PyConnector project implements the ability to bind the evaluation of nodes in FlexSim's tree to the evaluation of python functions. The project is implemented to work with python versions 3.7, 3.8, 3.9 and 3.10. The output DLLs from this project are included in the installed version of FlexSim.

(emphasis mine) and I found the DLLs in program\python so I assumed this should work out of the box.

I set the Python version in Global Preferences and made sure that python.exe is on my path. What am I missing? :-)

FlexSim 22.1.0
pythonuser command
flexsimpy.py (98 B)
test.fsm (26.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.

1 Answer

anthony.johnson avatar image
1 Like"
anthony.johnson answered Mischa Spelt commented

This is similar to this stack overflow question. First, you need to use dots instead of slashes as your path separators. So your module specifier should be "FlexSimPy.FlexSimPy" instead of "FlexSimPy/FlexSimPy". Second, in the folder where you put your FlexSimPy.py file, you need to have a blank file called __init__.py. Placing that file there signifies to python that this is a 'submodule' folder, so it can find the appropriate files.

I'll update the documentation to reflect this.

· 4
5 |100000

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