question

MPeyman avatar image
0 Likes"
MPeyman asked MPeyman commented

read python file in flexsim

Dear All, I wanted to try to add the global table from my python file but after many tries I couldn't and I get this error: ( also I created an empty python file as mentioned in other questions called __init__.py but it didn't work)

exception: Code Binding Error: could not bind to function

Node: /Tools/UserCommands/getData/code

Binding string: /**external python: */ /**/"InputGenerator_nodes2"/**/

/** \nfunction name:*/ /**/"read_location_data"/**/

Windows Error Code : 1400


Here I attached the files:

InputGenerator_nodes2.py

try1.fsm


Function: read_location_data()

getData("Instances","p1.2.a.txt").as(Array).as(Table).cloneTo(Table("GlobalTable1"))


FlexSim 23.0.8
flexsim python
try1.fsm (25.2 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.

1 Answer

Kavika F avatar image
0 Likes"
Kavika F answered MPeyman commented

Hey @MPeyman, the error you're getting suggests to me that your names python file name doesn't match the "external python" name. If you fix the name of your file to match the one in the data, then it should work.

1705511168108.png

1705511177427.png

Another note: your User Command "getData" takes in 2 parameters, but your python function doesn't take any. You may want to add those parameters to your python function if you'd like to pass them in. Otherwise you'll get this error:

read_location_data() takes 0 positional arguments but 2 were given


1705511168108.png (6.9 KiB)
1705511177427.png (2.1 KiB)
· 7
5 |100000

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

MPeyman avatar image MPeyman commented ·

dear @Kavika F , actually the name of the file is match, when I attached the file here it changed. However I checked again and removed the parameters and I got this error:

exception: Code Binding Error: could not bind to function

Node: /Tools/UserCommands/getData/code

Binding string: /**external python: */ /**/"InputGenerator-nodes2"/**/

/** \nfunction name:*/ /**/"read_location_data"/**/

Windows Error Code : 0


and when I try again I have this:

exception: Code Binding Error: could not bind to function

Node: /Tools/UserCommands/getData/code

Binding string: /**external python: */ /**/"InputGenerator-nodes2"/**/

/** \nfunction name:*/ /**/"read_location_data"/**/

Windows Error Code : 1400


So I start to make it all again and now I have this error:

exception: FlexScript exception: Array index out of bounds at <no path> c: <no path> i: <no path>


0 Likes 0 ·
Kavika F avatar image Kavika F ♦ MPeyman commented ·
@MPeyman, please show screenshots of your file names and how you've set things up. I was able to get the files you attached to run by simply changing the names of the files.


If you're starting over, that's fine too. The "Array index out of bounds" error means that you're trying to access an element in a FlexSim Array that is out of bounds.

0 Likes 0 ·
MPeyman avatar image MPeyman Kavika F ♦ commented ·

Dear @Kavika F , Here I attached the Screen shot and also the files you asked:

Step1.png

step2.png

Folder_file.png

Script.png

Error.png

UserCommand.png

Generator.py

Test_Py.fsm

0 Likes 0 ·
step1.png (157.1 KiB)
step2.png (119.1 KiB)
folder-file.png (17.2 KiB)
script.png (3.8 KiB)
error.png (11.8 KiB)
usercommand.png (63.1 KiB)
generator.py (998 B)
test-py.fsm (24.4 KiB)
Show more comments