FlexSim unable to bind external Python function (Code Binding Error)

FlexSim unable to bind external Python function (Code Binding Error)

marco_ricci42
Observer Observer
300 Views
1 Reply
Message 1 of 2

FlexSim unable to bind external Python function (Code Binding Error)

marco_ricci42
Observer
Observer

 

Hi everyone,

 

I’m trying to use FlexSim’s feature to call external Python code from within a FlexSim model (FlexSim version 25.2). Specifically, I want to call a Python module named PyMod which contains a function PyFunc.

I tried two different approaches, both using Process Flow:

 

Attempt 1 — Custom Code block (externally linked code)

In Process Flow I used a Custom Code activity and enabled Make Code Externally Linked. Inside that block I added the following binding:

 

/**external python: */ /**/"PyMod"/**/
/** \nfunction name:*/ /**/"PyFunc"/**/

 

This Custom Code activity is connected to a previous Source, so that a token arrives and triggers execution.
 

Attempt 2 — User Command + Assign Label

I created a User Command called CallPython with the same external Python binding:

 

/**external python: */ /**/"PyMod"/**/
/** \nfunction name:*/ /**/"PyFunc"/**/

 

Then, in Process Flow, I used an Assign Label activity that creates a label named test with value CallPython().

(I leave the parentheses empty because the Python function does not require arguments.)
This Assign Label is also connected to a Source so a token reaches it.

 

At the moment my Python file is just a test and should return a simple string:

 

# PyMod.py

def PyFunc():

        return "OK from Python"

 

I checked the Python version installed on my PC and the one selected in FlexSim, and they match (Python 3.12).

 

In both attempts, when I press Run, FlexSim shows a message:

 

FlexSim was unable to load the connector for the python language.

 

And in the console I get:

 

exception: Code Binding Error: could not bind to function Node: /Tools/ProcessFlow/TaskExecuter1 Process/CallPython>variables/codeNode Binding string: /**external python: */ /**/"PyMod"/**/ /** \nfunction name:*/ /**/"PyFunc"/**/ Windows Error Code : 0
 

How can I fix this so FlexSim can successfully create the Python connection and run the external Python file?

Thanks in advance!

301 Views
1 Reply
Reply (1)
Message 2 of 2

G_Dhakshna_CCS
Enthusiast
Enthusiast
0 Likes